From fbd75260927c1325fa66579961e881d6deae55ce Mon Sep 17 00:00:00 2001 From: tophf Date: Sat, 2 Dec 2017 18:29:12 +0300 Subject: [PATCH] usercss: Alt-PgUp/PgDn go to prev/next @-moz-document --- edit/source-editor.js | 46 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/edit/source-editor.js b/edit/source-editor.js index 6aab98c7..b6090e32 100644 --- a/edit/source-editor.js +++ b/edit/source-editor.js @@ -143,9 +143,8 @@ function createSourceEditor(style) { cm.on('focus', () => hotkeyRerouter.setState(false)); cm.on('blur', () => hotkeyRerouter.setState(true)); - //if (prefs.get('editor.autocompleteOnTyping')) { - // setupAutocomplete(cm); - //} + CodeMirror.commands.prevEditor = cm => nextPrevMozDocument(cm, -1); + CodeMirror.commands.nextEditor = cm => nextPrevMozDocument(cm, 1); } function updateMeta() { @@ -277,6 +276,47 @@ function createSourceEditor(style) { return dirty.isDirty() || hadBeenSaved; } + function nextPrevMozDocument(cm, dir) { + const cursor = cm.getCursor(); + let line = cursor.line; + let found; + if (dir > 0) { + cm.doc.iter(cursor.line + 1, cm.doc.size, ({text}) => ++line && goFind(text)); + if (!found && cursor.line > 0) { + line = -1; + cm.doc.iter(0, cursor.line, ({text}) => ++line && goFind(text)); + } + } else { + let handle, parentLines; + let passesRemain = line < cm.doc.size - 1 ? 2 : 1; + while (passesRemain--) { + let indexInParent = 0; + while (line--) { + if (!indexInParent--) { + handle = cm.getLineHandle(line); + parentLines = handle.parent.lines; + indexInParent = parentLines.indexOf(handle); + } else { + handle = parentLines[indexInParent]; + } + if (goFind(handle.text)) { + return true; + } + } + line = cm.doc.size; + } + } + function goFind(text) { + const ch = text.indexOf('@-moz-document'); + if (ch >= 0 && cm.getTokenTypeAt({line, ch}) === 'def') { + cm.scrollIntoView({line: line + 1, ch}, Math.min(50, cm.display.scroller.clientHeight / 4)); + cm.setCursor(line, ch); + found = true; + return true; + } + } + } + return { replaceStyle, save,