Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// deselect any selected card because the cursor is no longer on a card
if (this.selectedCard && !editor.range.isBlank) {
this.deselectCard(this.selectedCard);
}
// if we have `code` or ~strike~ formatting to the left but not the right
// then toggle the formatting - these formats should only be creatable
// through the text expansions
toggleSpecialFormatEditState(editor);
// do not include the tail section if it's offset is 0
// fixes triple-click unexpectedly selecting two sections for section-level formatting
// https://github.com/bustle/mobiledoc-kit/issues/597
if (direction === 1 && !isCollapsed && tail.offset === 0 && tail.section.prev) {
let finalSection = tail.section.prev;
let newRange = new MobiledocRange(head, finalSection.tailPosition());
return editor.selectRange(newRange);
}
// pass the selected range through to the toolbar + menu components
this.set('selectedRange', editor.range);
this._scrollCursorIntoView();
},
function renderIntoAndFocusTail(editorElement, treeFn, options={}) {
let editor = renderInto(editorElement, treeFn, options);
editor.selectRange(new Range(editor.post.tailPosition()));
return editor;
}
run(editor) {
if (editor.range.focusedPosition.section.type === 'list-item' &&
editor.range.focusedPosition.section.prev &&
editor.range.focusedPosition.offset === 0) {
let prevSection = editor.range.focusedPosition.section.prev;
let range = new Range(prevSection.headPosition(), prevSection.tailPosition());
let markups = typeof prevSection.markupsInRange === 'function' ? prevSection.markupsInRange(range) : [];
let markup = markups.find(item => {
return item.attributes && item.attributes.href === NEW_LINE_HREF;
});
if (markup) {
editor.run(postEditor => postEditor.toggleMarkup(markup, range));
} else {
return false;
}
} else {
return false;
}
}
});
run(editor) {
let section = editor.range.focusedPosition.section;
let range = new Range(section.headPosition(), section.tailPosition());
let markups = typeof section.markupsInRange === 'function' ? section.markupsInRange(range) : [];
let markup = markups.find(item => {
return item.attributes && item.attributes.href === NEW_LINE_HREF;
});
if (section.type === 'list-item' &&
editor.range.focusedPosition.section.next &&
!markup) {
editor.run(postEditor => {
let markup = postEditor.builder.createMarkup('a', { href: NEW_LINE_HREF });
postEditor.insertTextWithMarkup(section.tailPosition(), String.fromCharCode(8203), [markup]);
});
} else {
return false;
}
}
});
this.editor.editor.run(postEditor => {
let range = new Range(this._lastActiveSection.headPosition(),this._lastActiveSection.tailPosition());
postEditor.toggleSection(tag, range);
});
this.propertyDidChange('_lastActiveSection');