Giter Site home page Giter Site logo

capnmidnight / primrose Goto Github PK

View Code? Open in Web Editor NEW
530.0 42.0 73.0 207.1 MB

A syntax-highlighting text editors that renders to an HTML5 Canvas

Home Page: https://www.primrosevr.com

License: Other

JavaScript 60.03% HTML 1.64% CSS 0.23% C# 18.78% TypeScript 19.28% BASIC 0.04%
javascript html5 object-oriented computer-graphics syntax-highlighting text-editor text-editor-for-web

primrose's Introduction

PRIMROSE TEXT EDITOR

Primrose is a syntax highlighting text editor that renders into an HTML5 Canvas element. This is particularly useful for texturing 3D objects in WebGL apps.

Features

  • International keyboard support (left-to-right rendering only)
  • Wide Unicode character-aware
  • Line numbering
  • Color theming
  • Syntax highlighting for:
    • JavaScript,
    • HTML, and
    • BASIC

Liscense

Primrose is free, open source software (MIT) and may readily be used with other FOSS projects.


Contributing

Conduct

First, please read the Conduct Policy.

Contributions

If you think you can be a polite person in accordance with the Conduct Policy, I'd be more than happy to add anyone who asks as a contributor. Just email me your profile info and a brief description of what you'd like to work on.


Getting started with Primrose

In a 2D page

Here is a basic example that creates an editor in a 2D web page.

index.html

<html>
   <body>
      <primrose style="width:50em;height:25em"></primrose>
   </body>
   <script type="module" src="node_modules/primrose/src/primrose.js"></script>
</html>

In a 3D WebGL app

Here is a basic example that creates an editor in a 3D WebGL app, using Three.js.

NOTE: While Primrose can manage most input events on its own, in WebGL contexts, it's not able to figure out what the user's pointer is pointing at. Mouse or VR motion controller support requires implementing Raycast-based picking on your own. However, Primrose does offer a simple interface for implementing pointer operations.


API

The documentation here represents the public API. Any properties, methods, functions, or classes not listed here are considered either internal state or deprecated features and may change or be removed at any time.


Primrose

The Primrose class extends the EventTarget class. It is a text editor control that renders to an HTML5 Canvas, using the CanvasRenderingContext2D API.

Importing

To get the Primrose class, import it from the package bundle:

import { Primrose } from "./node_modules/primrose/primrose.js";

There is also a minified version:

import { Primrose } from "./node_modules/primrose/primrose.min.js";

You can also import without package bundling, which is probably preferred if you intend to build your own bundle:

import { Primrose } from "./node_modules/primrose/src/primrose.js";

Constructor

You create a Primrose control in one of two ways. In creating the control, there are a set of options that you can specify. The two ways are:

In HTML

Create a <primrose> tag in your document before the page has loaded.

Specify the options as a comma seperated list of key-value pairs, each separated by an equals sign (=), on an attribute on the tag named data-options.

Example
<primrose data-options="lineNumbers=false;wordWrap=false"></primrose>
In JavaScript

Create a new instance of the Primrose class, passing the options as a JavaScript object

Example
new Primrose({ lineNumbers: false, wordWrap: false });
Options

The options object has the following fields:

  • element:(HTMLElement|HTMLCanvasElement|OffscreenCanvas) - Default: null - a document element or a canvas that represents the Primrose control. This can either be:
    • a <primrose> tag (which is a generic HTML tag in DOM), in which case the editor Canvas will be inserted into the <primrose> tag, or
    • an HTMLCanvasElement element or OffscreeCanvas object, in which case the editor will take control of the canvas.
    • null, which instructs Primrose to construct its own Canvas element. If OffscreenCanvas is available, that will be used instead of HTMLCanvasElement.
  • width:Number - Default: undefined - the scale-independent width of the canvas used when element is null
  • height:Number - Default: undefined - the scale-independent height of the canvas used when element is null
  • padding:Number - Default: 0 - the scale-independent amount of inset for rendering the contents from the edge of the canvas. This is useful for texturing objects where the texture edge cannot be precisely controlled.
  • fontSize:Number - Default: 16 - the scale-independent height to draw characters.
  • scaleFactor:Number - *Default: window.devicePixelRatio - A multiplicative factor for how large to scale the width, height, fontSize, and padding of the canvas, to improve rendering sharpness on high-resolution displays. With THREE.js, it's best to set this value to 1 and change the width, height, and fontSize manually.
  • readOnly:Boolean - Default: false - indicates whether or not the text editor should allow changes to its value.
  • multiLine:Boolean - Default: true - indicates whether or not the text editor should break long lines onto new lines.
  • scrollBars:Boolean - Default: true - indicates whether or not scroll bars should be rendered at the right and bottom in the control. If wordWrap is enabled, the bottom, horizontal scrollbar will not be rendered.
  • lineNumbers:Boolean - Default: true - indicates whether or not line numbers should be rendered on the left side of the control.
  • language:String - Default: "JavaScript" - A name for the type of syntax highlighting to perform. This value is not case-sensitive. Valid values are:
    • "basic" for Basic,
    • "bas" for Basic,
    • "html" for HTML,
    • "javascript" for JavaScript,
    • "js" for JavaScript,
    • "plaintext" for PlainText,
    • "txt" for PlainText
    • and any case-variation thereof.

Events

The events in Primrose are all of type Event, having no other properties set on them. The only way to register the events is to call addEventListener, i.e. there are no on### properties on the object for the event handlers.

  • change:Event - Fires when the text in the control has changed.
  • blur:Event - Fires when the control first loses focus. Calls to blur() while the control is not focused will not fire the blur event.
  • focus:Event - Fires when the control first gains focus. Calls to focus() while the control is focused will not fire the focus event.
  • over:Event - Fires when the control is first hovered over by a pointer.
  • out:Event - Fires the first time the controller is no longer hovered over by a pointer.
  • update:Event - Fires when the Primrose control finishes rendering.

Public Methods


addEventListener(type:String, handler:Function(evt:Event))

Add a listener for one of the event types listed above.

Example
const editor = new Primrose({
    element: document.querySelector("canvas")
});

function onChange(){
    console.log("changed!");
}

editor.addEventListener("change", onChange);
editor.value = "Something"; // 'changed!' printed out to console.
Parameters
  • name:String - The name of the event to register, one of the event names listed in the Events section above.
  • handler:Function(evt:Event) - A callback function to receive the event. This function will be provided an argument of type Event

removeEventListener(type:String, handler:Function(evt:Event))

Remove an event listener that was added with addEventListener()

Example
const editor = new Primrose({
    element: document.querySelector("canvas")
});

function onChange(){
    console.log("changed!");
}

editor.addEventListener("change", onChange);
editor.value = "Something"; // 'changed!' printed out to console.
editor.removeEventListener("change", onChange);
editor.value = "Something else"; // nothing printed out to console.

blur()

Removes focus from the control.

Example
const editor = new Primrose({
    element: document.querySelector("canvas")
});

function onBlur(){
    console.log("blurred!");
}

editor.addEventListener("blur", onBlur);
if(!editor.focused){
    editor.focus();
}
editor.blur(); // 'blurred!' printed out to console.
editor.blur(); // nothing printed out to console.
editor.focus();
editor.blur(); // 'blurred!' printed out to console.

focus()

Sets the control to be the focused control. If all controls in the app have been properly registered with the Event Manager, then any other, currently focused control will first get blur'd.

Example
const editor = new Primrose({
    element: document.querySelector("canvas")
});

function onFocus(){
    console.log("focused!");
}

editor.addEventListener("focused", onFocus);
if(editor.focused){
    editor.blur();
}
editor.focus(); // 'focused!' printed out to console.
editor.focus(); // nothing printed out to console.
editor.blur();
editor.focus(); // 'focused!' printed out to console.

scrollTo(x:Number, y:Number)

Move the scroll window to a new location. Values get clamped to the text contents of the editor.

Parameters
  • x - the horizontal position to which to scroll. If wordWrap is enabled, this has no effect.
  • y - the vertical position to which to scroll.
Return Value

true if the scrolling was clamped to the upper or lower bounds of the content, false otherwise.


scrollBy(dx:Number, dy:Number)

Move the scroll window by a given amount to a new location. The final location of the scroll window gets clamped to the text contents of the editor.

Parameters
  • dx - the horizontal offset by which to scroll. If wordWrap is enabled, this has no effect.
  • dy - the vertical offset by which to scroll.
Return Value

true if the scrolling was clamped to the upper or lower bounds of the content, false otherwise.


setSize(width:Number, height:Number)

Sets the scale-independent width and height of the editor control.

Example
const editor = new Primrose({
  width: 512,
  height: 512,
  scaleFactor: 2
});

if(editor.width === 512) { /* true */ }
if(editor.canvas.width === 1024) { /* true */}

editor.setSize(1024, 1024);
if(editor.width === 1024) { /* true */ }
if(editor.canvas.width === 2048) { /* true */}
Parameters
  • width - the nominal width of the editor canvas. This value is scaled by scaleFactor before actually setting the canvas width.
  • height - the nominal height of the editor canvas. This value is scaled by scaleFactor before actually setting the canvas height.

resize()

If the canvas element used by the editor control is in the document tree, this method forces the editor to check the client bounds of the DOM element and resize the rendering resolution of the canvas accordingly, to maintain rendering sharpness. Normally, this does not need to be called in user-code, as the Event Manager handles resizing.

If the canvas does not need to be resized, then no action occurs.


Public Properties

element:HTMLElement - read-only

The DOM element that was used to construct the Primrose control out of the document tree. If the Control was not constructed from the document tree, this value will be null.


isInDocument:Boolean - read-only

Returns false if element is null. Returns true otherwise.


canvas:(HTMLCanvasElement|OffscreenCanvas) - read-only

The canvas to which the editor is rendering text. If the options.element value was set to a canvas, that canvas will be returned. Otherwise, the canvas will be the canvas that Primrose created for the control. If OffscreenCanvas is not available, the canvas will be an HTMLCanvasElement.


hovered:Boolean - readOnly

Returns true when the control has a pointer hovering over it.


focused:Boolean - read/write

Returns true when the control has been selected. Writing to this value will change the focus state of the control.

If the control is already focused and focused is set to true, or the control is not focused and focus is set to false, nothing happens.

If the control is focused and focused is set to false, the control is blurred, just as if blur() was called.

If the control is not focused and focused is set to true, the control is focused, just as if focus() was called.


readOnly:Boolean - read/write

Indicates whether or not the text in the editor control can be modified.


wordWrap:Boolean - read/write

Indicates whether or not the text in the editor control will be broken across lines when it reaches the right edge of the editor control.


value:String - read/write

The text value contained in the control. NOTE: if the text value was set with Windows-style newline characters (\r\n), the newline characters will be normalized to Unix-style newline characters (\n).


text:String - read/write

A synonymn for value


selectedText:String - read/write

The range of text that is currently selected by the cursor. If no text is selected, reading selectedText returns the empty string ("") and writing to it inserts text at the current cursor location. If text is selected, reading selectedText returns the text between the front and back cursors, writing to it overwrites the selected text, inserting the provided value.


selectionStart:Number - read/write

The string index at which the front cursor is located. NOTE: the "front cursor" is the main cursor, but does not necessarily represent the beginning of the selction range. The selection range runs from the minimum of front and back cursors, to the maximum.


selectionEnd:Number - read/write

The string index at which the back cursor is located. NOTE: the "back cursor" is the selection range cursor, but does not necessarily represent the end of the selction range. The selection range runs from the minimum of front and back cursors, to the maximum.


selectionDirection:String - read-only

If the back cursor is behind the front cursor, this value returns "backward". Otherwise, "forward" is returned.


tabWidth:Number - read/write

The number of spaces to insert when the Tab key is pressed. Changing this value does not convert existing tabs, it only changes future tabs that get inserted.


theme:Theme - read/write

A JavaScript object that defines the color and style values for rendering different UI and text elements.


language:Grammar - read/write

Set or get the language pack used to tokenize the control text for syntax highlighting.

Example
import { Primrose, JavaScript, HTML } from "./package/primrose.min.js";

const editor = new Primrose({
    elem: document.querySelector("canvas")
});

if(editor.language === JavaScript) { /* true */ }

editor.language = HTML;

if(editor.language === HTML) { /* true */ }

padding:Number - read/write

The Number of pixels to inset the control rendering from the edge of the canvas. This is useful for texturing objects where the texture edge cannot be precisely controlled. This value is scale-independent.


showLineNumbers:Boolean - read/write

Indicates whether or not line numbers should be rendered on the left side of the control.


showScrollBars:Boolean - read/write

Indicates whether or not scroll bars should be rendered at the right and bottom in the control. If wordWrap is enabled, the bottom, horizontal scrollbar will not be rendered.


fontSize:Number - read/write

The Number of pixels tall to draw characters. This value is scale-independent.

Example
const editor = new Primrose({
  element: document.querySelector("canvas")
});

if(editor.fontSize === 16) { /* default value */ }

editor.fontSize = 24;

if(editor.fontSize === 24) { /* true */ }

editor.scaleFactor = 2;

if(editor.fontSize === 24) { /* true */ }

scaleFactor:Number - read/write

The value by which pixel values are scaled before being used by the editor control.

With THREE.js, it's best to set this value to 1 and change the width, height, and fontSize manually.

Example
const editor = new Primrose({
  width: 512,
  height: 512,
  scaleFactor: 1
});

if(editor.width === 512) { /* true */ }
if(editor.canvas.width === 512) { /* true */ }

editor.scaleFactor = 2;

if(editor.width === 512) { /* true */ }
if(editor.canvas.width === 1024) { /* true */ }

width:Number - read/write

The scale-independent width of the editor control.

Example
const editor = new Primrose({
  width: 512,
  height: 512,
  scaleFactor: 2
});

if(editor.width === 512) { /* true */ }
if(editor.canvas.width === 1024) { /* true */}

height:Number - read/write

The scale-independent height of the editor control.

Example
const editor = new Primrose({
  width: 512,
  height: 512,
  scaleFactor: 2
});

if(editor.height === 512) { /* true */ }
if(editor.canvas.height === 1024) { /* true */}

Pointer Event Handlers for WebGL Contexts

In 2D operation, you don't need to manually wire up any events. But in WebGL contexts, you will need to perform your own raycasting in response to user input gestures and tell Primrose how to translate those into pointer actions.

These events require a parameter value that is a Raycast intersection as provided by THREE.js. The intersection has a Vector2 property named uv that the event handlers read to determine the location of the pointer within the control. The uv.x field is scaled by the control's width property, and 1 - uv.y is scaled by the control's height property.

When implementing pointer events with VR Motion Controllers, you must decide if you want mouse-like our touch-like behavior.

Mouse-like Behavior
  • mouse.readOverEventUV(evt:THREE.Raycaster Intersection) - Read's a THREE.js Raycast intersection to perform the hover gestures.
  • mouse.readOutEventUV(evt:THREE.Raycaster Intersection) - Read's a THREE.js Raycast intersection to perform the end of the hover gesture.
  • mouse.readDownEventUV(evt:THREE.Raycaster Intersection) - Read's a THREE.js Raycast intersection to perform mouse-like behavior for primary-button-down gesture.
  • mouse.readUpEventUV(evt:THREE.Raycaster Intersection) - Read's a THREE.js Raycast intersection to perform mouse-like behavior for primary-button-up gesture.
  • mouse.readMoveEventUV(evt:THREE.Raycaster Intersection) - Read's a THREE.js Raycast intersection to perform mouse-like behavior for move gesture, whether the primary button is pressed or not.
Touch-like Behavior
  • touch.readOverEventUV(evt:THREE.Raycaster Intersection) - Read's a THREE.js Raycast intersection to perform the hover gestures. This is the same as mouse.readOverEventUV, included for completeness.
  • touch.readOutEventUV(evt:THREE.Raycaster Intersection) - Read's a THREE.js Raycast intersection to perform the end of the hover gesture. This is the same as mouse.readOutEventUV, included for completeness.
  • touch.readStartEventUV(evt:THREE.Raycaster Intersection) - Read's a THREE.js Raycast intersection to perform touch-like behavior for the first finger touching down gesture.
  • touch.readEndEventUV(evt:THREE.Raycaster Intersection) - Read's a THREE.js Raycast intersection to perform touch-like behavior for the first finger raising up gesture.
  • touch.readMoveEventUV(evt:THREE.Raycaster Intersection) - Read's a THREE.js Raycast intersection to perform touch-like behavior for the first finger moving gesture.

Static Methods

These are methods that exist on the Primrose class itself.


Primrose.add(key:any, control:Primrose)

Registers a new Primrose editor control with the Event Manager, to wire-up key, clipboard, and mouse wheel events, and to manage the currently focused element.

The Event Manager maintains the references in a WeakMap, so when the JS Garbage Collector collects the objects, they will be gone.

Multiple objects may be used to register a single control with the Event Manager without causing issue. This is useful for associating the control with closed objects from other systems, such as Three.js Mesh objects being targeted for pointer picking.

If you are working with Three.js, it's recommended to use the Mesh on which you are texturing the canvas as the key when adding the editor to the Event Manager.

Example
// with an existing canvas
const editor = new Primrose({
  element: document.querySelector("canvas"),
  scaleFactor: devicePixelRatio
});

Primrose.add("myOwnKeyOfAnyKind", editor);
Parameters
  • key - an arbitrary object that can be used to retrieve the editor back out again.
  • control - an instance of the Primrose class.
Retrun Value

Undefined


Primrose.has(key:any):Boolean

Checks for the existence of a control, by the key that the user supplied when calling Primrose.add()

Example
// with an existing canvas
const editor = new Primrose({
  element: document.querySelector("canvas"),
  scaleFactor: devicePixelRatio
});

const key = new Object();
Primrose.add(key, editor);
Primrose.has(key); // true
Primrose.has("SomeOtherKey"); // false
Parameters
  • key - the key that was used to add the control to the Event Manager.
Return Value
  • true if the key maps to a control in the Event Manager.
  • false if the given key was not used to register a control with the Event Manager.

Primrose.get(key:any):Primrose

Gets the control associated with the given key.

Example
// with an existing canvas
const editor = new Primrose({
  element: document.querySelector("canvas"),
  scaleFactor: devicePixelRatio
});

const key = new Object();
Primrose.add(key, editor);
const ed1 = Primrose.get(key);
if(editor === ed1) { /* true */ }
if(Primrose.get("anyOtherKey") === null) { /* true */}
Parameters
  • key - the key that was used to add the control to the Event Manager.
Return Value
  • null if no control in the Event Manager matches the given key.
  • a Primrose control, otherwise.

Static Properties

These are properties on the Primrose class itself.


Primrose.hoveredControl:Primrose - read-only

The current Primrose control that has the mouse hovered over it. In 2D contexts, you probably don't need to check this value, but in WebGL contexts, this is useful for helping Primrose manage events.

If no control is hovered, this returns null.


Primrose.focusedControl:Primrose - read-only

The current Primrose control that has pointer-focus. It will receive all keyboard and clipboard events. In 2D contexts, you probably don't need to check this value, but in WebGL contexts, this is useful for helping Primrose manage events.

If no control is focused, this returns null.


Primrose.editors:Array of Primrose - read-only

An array of all of the Primrose editor controls that Primrose currently knows about.

This array is not mutable and is not the array used by the Event Manager. It is a read-only clone that is created whenever the Event Manager registers or removes a new control


Primrose.ready:Promise - read-only

A Promise that resolves when the document is ready and the Event Manager has finished its initial setup.


Theme

Themes control the rendering of text and UI elements within the Primrose control. Themes are JavaScript objects that match the following pattern. All fields are required; there are no optional fields.

Example

{
    name: "Dark",
    cursorColor: "white",
    lineNumbers: {
        foreColor: "white"
    },
    regular: {
        backColor: "black",
        foreColor: "#c0c0c0",
        currentRowBackColor: "#202020",
        selectedBackColor: "#404040",
        unfocused: "rgba(0, 0, 255, 0.25)"
    },
    strings: {
        foreColor: "#aa9900",
        fontStyle: "italic"
    },
    regexes: {
        foreColor: "#aa0099",
        fontStyle: "italic"
    },
    numbers: {
        foreColor: "green"
    },
    comments: {
        foreColor: "yellow",
        fontStyle: "italic"
    },
    keywords: {
        foreColor: "cyan"
    },
    functions: {
        foreColor: "brown",
        fontWeight: "bold"
    },
    members: {
        foreColor: "green"
    },
    error: {
        foreColor: "red",
        fontStyle: "underline italic"
    }
}

Grammar

Grammars are collections of RegExps that define rules for performing the necessary tokenization to be able to achieve syntax highlighting. The token types roughly correspond to coloring settings in the Themes They can be quite difficult to develop. Following the example below, implement each of the token types as necessary for the language you would like to parse.

Each Grammar rule is applied in sequence. In the example below, regexes is applied before stringDelim, giving priority to matching regular expressions over string literals, and stringDelim occurs before numbers, so that numbers inside of strings do not erroneously get matched as numbers.

The supported types of tokens are:

  • lineNumbers - for languages like BASIC that have explicit line-numbering, the lineNumbers token type extra
  • startBlockComments - for languages that have block-delimited commenting, like JavaScripts /* */, use this rule to match the beginning of the block comment.
  • endBlockComments - for languages that have block-delimited commenting, like JavaScripts /* */, use this rule to match the end of the block comment.
  • regexes - for languages that have built-in literal syntax for Regular Expressions.
  • stringDelim - use this rule to provide a list of tokens that delimit string literals.
  • startLineComments - for language with line-ending commenting, like JavaScripts //, use this rule to match the beginning of the comment. The comment will then run to the first newline character (hence one of the reasons newline get matched first).
  • numbers - use this rule to match integer and decimal numbers prior to matching any other keywords or identifiers that may contain numbers.
  • keywords - use this rule to match language keywords, like for or let in JavaScript.
  • functions - use this rule to match function expressions.
  • members - use this rule to match identifiers that are accessed from an object.

Additionally, there are newlines, whitespace, and regular-type tokens. The newlines and whitespace types are provided by default by the Grammar class. The regular type is a catch-all type for any text that does not match any previous rule.

NOTE: there is no general-purpose means by which we can gain perfect understanding of every language's syntax. The Grammar system provided by Primrose is meant for a high-level, textual understanding of language and not meant to completely parse and understand the structure of the program.

Example

export const JavaScript = new Grammar("JavaScript", [
    ["newlines", /(?:\r\n|\r|\n)/],
    ["whitespace", /(?:\s+)/],
    ["startBlockComments", /\/\*/],
    ["endBlockComments", /\*\//],
    ["regexes", /(?:^|,|;|\(|\[|\{)(?:\s*)(\/(?:\\\/|[^\n\/])+\/)/],
    ["stringDelim", /("|'|`)/],
    ["startLineComments", /\/\/.*$/m],
    ["numbers", /-?(?:(?:\b\d*)?\.)?\b\d+\b/],
    ["keywords",
        /\b(?:break|case|catch|class|const|continue|debugger|default|delete|do|else|export|finally|for|function|if|import|in|instanceof|let|new|return|super|switch|this|throw|try|typeof|var|void|while|with)\b/
    ],
    ["functions", /(\w+)(?:\s*\()/],
    ["members", /(\w+)\./],
    ["members", /((\w+\.)+)(\w+)/]
]);

primrose's People

Contributors

capnmidnight avatar chobberoni avatar jzitelli avatar kbouw avatar kehindeayan avatar markopp avatar micahbales avatar thomcc avatar upodroid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

primrose's Issues

create "viewports" on canvas, and let multiple editors edit the same logical canvas

Primrose is going to eventually become just a text buffer with simple styling rules, and the Editor parts of it will eventually become a separate class that drives the text buffer. This will open up room for other such driver programs to do other tasks, like displaying file browsers, or terminal emulators.

By having a "viewport" notion for a text buffer, the user will not necessarily have to create multiple textures to use all of those future features.

Create focus-order list feature

create a keyboard shortcut of some kind that lets a user change focus easily when the user has multiple focus elements available as options,

Only works in Google Chrome

Using the CSSStyleSheet object from the DOM is causing browser compatibility issues. Using DOM to parse the HTML is probably over-complicating things as well. We're already lexing and parsing the document to figure out the syntax highlighting, why make the browser do it again? Just create a simplified styling system. This doesn't have to be the best thing in the world, just easy to use.

Uncompatible with Vimium extension

Usually textboxes don't interfere with the vimium extension, but because there is no input box to capture keystrokes, the vimium captures keystrokes before inputting.
Solutions could be:

  1. An hidden but focused textbox to capture keystrokes
  2. Prevent default when "focused" on canvas

Create scrollbars

When text gets too long or wide for the viewport, scrollbars should appear.

Write a full license file

Include it, with the user's license number, with a copy of the primrose source file, in a zip file that downloads automatically when the user buys a copy.

Use a proper rope data structure

It currently edits text as an array of lines. This makes reasoning about edits difficult, and will encourage code duplication.

Support international keyboards

Most of the scaffolding is in place for this. Still to do:

  • [] Convert to using regex-based routing for keyboard commands, rather than strict string-match. That should reduce the amount of repetition.
  • [] Track the state of the CTRL, ALT, and SHIFT keys manually, when they fire their own keyCodes on keyDown and keyUp.
  • [] Include the KeyboardEvent::location || KeyboardEvent::keyLocation value in the tracking, to separately track left- and right-modifier keys.
  • [] Create a key sequencing system to be able to skip printing anything for dead keys (http://en.wikipedia.org/wiki/Dead_key), then printing only one character for the following key, the key that the dead key modifies.

Create a keyboard command system

The editor's default commands should be implemented in the same system that implementors would use to include their own functionality.

Regular cursor movement is broken

The caret moves correctly, but the insertion point doesn't keep up with the caret. Also, it causes out-of-bounds errors at the ends of the text.

No support for IMEs

If you're Japanese, Chinese, Korean, Thai, etc your S.O.L. at the moment. I don't know if there's a reasonable solution but google sheets handles this case as an example an they are also rendering to a canvas.

google sheets

Viewports

The Canvas area should be divisible into sub viewports, with text drawing taking place in them separately.

Support Unicode ALT codes

provide a keyboard shortcut to enter 4-digit unicode sequences to insert unicode characters.

Use String.fromCodePoint when available, fromCharCode otherwise.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.