mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-30 04:23:11 +03:00
ESLINT: Addressed remaining detected issues
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import DrawIO from '../services/drawio';
|
||||
import * as DrawIO from '../services/drawio';
|
||||
|
||||
export class Actions {
|
||||
|
||||
@ -140,7 +140,7 @@ export class Actions {
|
||||
} else {
|
||||
window.$events.emit('error', this.editor.config.text.imageUploadError);
|
||||
}
|
||||
console.log(error);
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
// Make the editor full screen
|
||||
@ -165,7 +165,7 @@ export class Actions {
|
||||
scrollToLine = lineCount;
|
||||
break;
|
||||
}
|
||||
lineCount++;
|
||||
lineCount += 1;
|
||||
}
|
||||
|
||||
if (scrollToLine === -1) {
|
||||
@ -258,22 +258,31 @@ export class Actions {
|
||||
* @param {String} end
|
||||
*/
|
||||
wrapSelection(start, end) {
|
||||
const selectionRange = this.#getSelectionRange();
|
||||
const selectionText = this.#getSelectionText(selectionRange);
|
||||
if (!selectionText) return this.#wrapLine(start, end);
|
||||
const selectRange = this.#getSelectionRange();
|
||||
const selectionText = this.#getSelectionText(selectRange);
|
||||
if (!selectionText) {
|
||||
this.#wrapLine(start, end);
|
||||
return;
|
||||
}
|
||||
|
||||
let newSelectionText = selectionText;
|
||||
let newRange;
|
||||
|
||||
if (selectionText.startsWith(start) && selectionText.endsWith(end)) {
|
||||
newSelectionText = selectionText.slice(start.length, selectionText.length - end.length);
|
||||
newRange = selectionRange.extend(selectionRange.from, selectionRange.to - (start.length + end.length));
|
||||
newRange = selectRange.extend(selectRange.from, selectRange.to - (start.length + end.length));
|
||||
} else {
|
||||
newSelectionText = `${start}${selectionText}${end}`;
|
||||
newRange = selectionRange.extend(selectionRange.from, selectionRange.to + (start.length + end.length));
|
||||
newRange = selectRange.extend(selectRange.from, selectRange.to + (start.length + end.length));
|
||||
}
|
||||
|
||||
this.#dispatchChange(selectionRange.from, selectionRange.to, newSelectionText, newRange.anchor, newRange.head);
|
||||
this.#dispatchChange(
|
||||
selectRange.from,
|
||||
selectRange.to,
|
||||
newSelectionText,
|
||||
newRange.anchor,
|
||||
newRange.head,
|
||||
);
|
||||
}
|
||||
|
||||
replaceLineStartForOrderedList() {
|
||||
@ -314,7 +323,13 @@ export class Actions {
|
||||
const newFormat = formats[newFormatIndex];
|
||||
const newContent = line.text.replace(matches[0], matches[0].replace(format, newFormat));
|
||||
const lineDiff = newContent.length - line.text.length;
|
||||
this.#dispatchChange(line.from, line.to, newContent, selectionRange.anchor + lineDiff, selectionRange.head + lineDiff);
|
||||
this.#dispatchChange(
|
||||
line.from,
|
||||
line.to,
|
||||
newContent,
|
||||
selectionRange.anchor + lineDiff,
|
||||
selectionRange.head + lineDiff,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -399,7 +414,7 @@ export class Actions {
|
||||
} catch (err) {
|
||||
window.$events.emit('error', this.editor.config.text.imageUploadError);
|
||||
this.#findAndReplaceContent(placeHolderText, '');
|
||||
console.log(err);
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
@ -432,7 +447,8 @@ export class Actions {
|
||||
*/
|
||||
#replaceSelection(newContent, cursorOffset = 0, selectionRange = null) {
|
||||
selectionRange = selectionRange || this.editor.cm.state.selection.main;
|
||||
this.#dispatchChange(selectionRange.from, selectionRange.to, newContent, selectionRange.from + cursorOffset);
|
||||
const selectFrom = selectionRange.from + cursorOffset;
|
||||
this.#dispatchChange(selectionRange.from, selectionRange.to, newContent, selectFrom);
|
||||
this.focus();
|
||||
}
|
||||
|
||||
@ -510,6 +526,9 @@ export class Actions {
|
||||
|
||||
if (selectFrom) {
|
||||
tr.selection = {anchor: selectFrom};
|
||||
if (selectTo) {
|
||||
tr.selection.head = selectTo;
|
||||
}
|
||||
}
|
||||
|
||||
this.editor.cm.dispatch(tr);
|
||||
|
@ -21,7 +21,9 @@ export async function init(editor) {
|
||||
|
||||
const onScrollDebounced = debounce(editor.actions.syncDisplayPosition.bind(editor.actions), 100, false);
|
||||
let syncActive = editor.settings.get('scrollSync');
|
||||
editor.settings.onChange('scrollSync', val => syncActive = val);
|
||||
editor.settings.onChange('scrollSync', val => {
|
||||
syncActive = val;
|
||||
});
|
||||
|
||||
const domEventHandlers = {
|
||||
// Handle scroll to sync display view
|
||||
|
@ -21,7 +21,7 @@ export class Settings {
|
||||
|
||||
listenToInputChanges(inputs) {
|
||||
for (const input of inputs) {
|
||||
input.addEventListener('change', event => {
|
||||
input.addEventListener('change', () => {
|
||||
const name = input.getAttribute('name').replace('md-', '');
|
||||
this.set(name, input.checked);
|
||||
});
|
||||
|
@ -7,35 +7,35 @@ function provide(editor) {
|
||||
const shortcuts = {};
|
||||
|
||||
// Insert Image shortcut
|
||||
shortcuts['Shift-Mod-i'] = cm => editor.actions.insertImage();
|
||||
shortcuts['Shift-Mod-i'] = () => editor.actions.insertImage();
|
||||
|
||||
// Save draft
|
||||
shortcuts['Mod-s'] = cm => window.$events.emit('editor-save-draft');
|
||||
shortcuts['Mod-s'] = () => window.$events.emit('editor-save-draft');
|
||||
|
||||
// Save page
|
||||
shortcuts['Mod-Enter'] = cm => window.$events.emit('editor-save-page');
|
||||
shortcuts['Mod-Enter'] = () => window.$events.emit('editor-save-page');
|
||||
|
||||
// Show link selector
|
||||
shortcuts['Shift-Mod-k'] = cm => editor.actions.showLinkSelector();
|
||||
shortcuts['Shift-Mod-k'] = () => editor.actions.showLinkSelector();
|
||||
|
||||
// Insert Link
|
||||
shortcuts['Mod-k'] = cm => editor.actions.insertLink();
|
||||
shortcuts['Mod-k'] = () => editor.actions.insertLink();
|
||||
|
||||
// FormatShortcuts
|
||||
shortcuts['Mod-1'] = cm => editor.actions.replaceLineStart('##');
|
||||
shortcuts['Mod-2'] = cm => editor.actions.replaceLineStart('###');
|
||||
shortcuts['Mod-3'] = cm => editor.actions.replaceLineStart('####');
|
||||
shortcuts['Mod-4'] = cm => editor.actions.replaceLineStart('#####');
|
||||
shortcuts['Mod-5'] = cm => editor.actions.replaceLineStart('');
|
||||
shortcuts['Mod-d'] = cm => editor.actions.replaceLineStart('');
|
||||
shortcuts['Mod-6'] = cm => editor.actions.replaceLineStart('>');
|
||||
shortcuts['Mod-q'] = cm => editor.actions.replaceLineStart('>');
|
||||
shortcuts['Mod-7'] = cm => editor.actions.wrapSelection('\n```\n', '\n```');
|
||||
shortcuts['Mod-8'] = cm => editor.actions.wrapSelection('`', '`');
|
||||
shortcuts['Shift-Mod-e'] = cm => editor.actions.wrapSelection('`', '`');
|
||||
shortcuts['Mod-9'] = cm => editor.actions.cycleCalloutTypeAtSelection();
|
||||
shortcuts['Mod-p'] = cm => editor.actions.replaceLineStart('-');
|
||||
shortcuts['Mod-o'] = cm => editor.actions.replaceLineStartForOrderedList();
|
||||
shortcuts['Mod-1'] = () => editor.actions.replaceLineStart('##');
|
||||
shortcuts['Mod-2'] = () => editor.actions.replaceLineStart('###');
|
||||
shortcuts['Mod-3'] = () => editor.actions.replaceLineStart('####');
|
||||
shortcuts['Mod-4'] = () => editor.actions.replaceLineStart('#####');
|
||||
shortcuts['Mod-5'] = () => editor.actions.replaceLineStart('');
|
||||
shortcuts['Mod-d'] = () => editor.actions.replaceLineStart('');
|
||||
shortcuts['Mod-6'] = () => editor.actions.replaceLineStart('>');
|
||||
shortcuts['Mod-q'] = () => editor.actions.replaceLineStart('>');
|
||||
shortcuts['Mod-7'] = () => editor.actions.wrapSelection('\n```\n', '\n```');
|
||||
shortcuts['Mod-8'] = () => editor.actions.wrapSelection('`', '`');
|
||||
shortcuts['Shift-Mod-e'] = () => editor.actions.wrapSelection('`', '`');
|
||||
shortcuts['Mod-9'] = () => editor.actions.cycleCalloutTypeAtSelection();
|
||||
shortcuts['Mod-p'] = () => editor.actions.replaceLineStart('-');
|
||||
shortcuts['Mod-o'] = () => editor.actions.replaceLineStartForOrderedList();
|
||||
|
||||
return shortcuts;
|
||||
}
|
||||
|
Reference in New Issue
Block a user