How to use the @typewriter/editor.getLines function in @typewriter/editor

To help you get started, we’ve selected a few @typewriter/editor examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github typewriter-editor / typewriter / packages / view / src / decorators.ts View on Github external
line(at: number, attributes: { [name: string]: any }) {
    const line = getLines(this.contents, at, at)[0];
    if (!line) return;
    this.updatePosition(line.end - 1);
    this.delta.retain(1, { decorator: attributes });
    this.position += 1;
  }
github typewriter-editor / typewriter / packages / modules / src / input.ts View on Github external
function onTab(event: CustomEvent) {
      if (event.defaultPrevented) return;
      event.preventDefault();
      const shortcut = event.detail;

      const direction = shortcut === 'Tab' || shortcut === 'Mod+]' ? 1 : -1;
      const range = editor.getSelectedRange();
      if (!range) return;
      const [ from, to ] = range;
      const lines: Line[] = getLines(editor.contents, from, to);

      editor.transaction(() => {
        lines.forEach(line => {
          const block = paper.blocks.findByAttributes(line.attributes) || paper.blocks.getDefault();
          if (block.indentable) {
            const indent = (line.attributes.indent || 0) + direction;
            const range: EditorRange = [ line.start, line.start ];
            if (indent < 0) {
              editor.formatLine(range, {});
            } else {
              const attributes = { ...line.attributes, indent };
              editor.formatLine(range, attributes);
            }
          }
        });
      }, SOURCE_USER);

@typewriter/editor

The core editor for typewriter. Manages the data model and updates. Can be run headless.

MIT
Latest version published 4 years ago

Package Health Score

51 / 100
Full package analysis