Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
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);