Sha256: a19d33d85573cebc5ff5679075962bc26aa18d363495d82c3feb2434d20a4fc9

Contents?: true

Size: 1.76 KB

Versions: 31

Compression:

Stored size: 1.76 KB

Contents

/* eslint-disable require-jsdoc */

import attributeDiff from "src/decidim/editor/attribute_diff"

export default function backspaceBindingsRangeAny(quill) {
  quill.keyboard.addBinding({ key: 8, altKey: null, ctrlKey: null, metaKey: null, shiftKey: null, collapsed: true }, (range, context) => {
    let length = 1;
    if (range.index === 0 || quill.getLength() <= 1) {
      return;
    }
    let [line] = quill.getLine(range.index);
    let formats = {};
    if (context.offset === 0) {
      let [prev] = quill.getLine(range.index - 1);
      if (prev !== null && prev.length() > 1) {
        let curFormats = line.formats();
        let prevFormats = quill.getFormat(range.index - 1, 1);
        formats = attributeDiff(curFormats, prevFormats) || {};
        const previousLineLength = quill.getLine(range.index - 1)[1];
        const previousChar = quill.getText(range.index - 1, 1)
        const beforePreviousChar = quill.getText(range.index - 2, 1);
        if (previousLineLength && previousLineLength === 1 && beforePreviousChar === "\n") {
          if (prevFormats && prevFormats.list) {
            quill.setSelection(range.index - 2, Quill.sources.SILENT);
          } else if (previousChar === "\n" && beforePreviousChar === "\n") {
            length += 1;
          }
        }
      }
    }

    if ((/[\uD800-\uDBFF][\uDC00-\uDFFF]$/).test(context.prefix)) {
      length += 1;
    }
    quill.deleteText(range.index - length, length, Quill.sources.USER);

    if (Object.keys(formats).length > 0) {
      quill.formatLine(range.index - length, length, formats, Quill.sources.USER);
    }
    quill.focus();
  })

  // Put this backspace binding to second (after backspce_offset1 it's going to be third)
  quill.keyboard.bindings[8].splice(1, 0, quill.keyboard.bindings[8].pop());
}

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
decidim-core-0.27.9 app/packs/src/decidim/editor/modified_backspace_offset_any.js
decidim-core-0.27.8 app/packs/src/decidim/editor/modified_backspace_offset_any.js
decidim-core-0.27.7 app/packs/src/decidim/editor/modified_backspace_offset_any.js
decidim-core-0.27.6 app/packs/src/decidim/editor/modified_backspace_offset_any.js
decidim-core-0.26.10 app/packs/src/decidim/editor/modified_backspace_offset_any.js
decidim-core-0.26.9 app/packs/src/decidim/editor/modified_backspace_offset_any.js
decidim-core-0.27.5 app/packs/src/decidim/editor/modified_backspace_offset_any.js
decidim-core-0.26.8 app/packs/src/decidim/editor/modified_backspace_offset_any.js
decidim-core-0.27.4 app/packs/src/decidim/editor/modified_backspace_offset_any.js
decidim-core-0.27.3 app/packs/src/decidim/editor/modified_backspace_offset_any.js
decidim-core-0.26.7 app/packs/src/decidim/editor/modified_backspace_offset_any.js
decidim-core-0.26.5 app/packs/src/decidim/editor/modified_backspace_offset_any.js
decidim-core-0.27.2 app/packs/src/decidim/editor/modified_backspace_offset_any.js
decidim-core-0.27.1 app/packs/src/decidim/editor/modified_backspace_offset_any.js
decidim-core-0.26.4 app/packs/src/decidim/editor/modified_backspace_offset_any.js
decidim-core-0.27.0 app/packs/src/decidim/editor/modified_backspace_offset_any.js
decidim-core-0.26.3 app/packs/src/decidim/editor/modified_backspace_offset_any.js
decidim-core-0.27.0.rc2 app/packs/src/decidim/editor/modified_backspace_offset_any.js
decidim-core-0.27.0.rc1 app/packs/src/decidim/editor/modified_backspace_offset_any.js
decidim-core-0.26.2 app/packs/src/decidim/editor/modified_backspace_offset_any.js