From c635f2e38c447e88a0bb5ba8cfe56ed4cdf12f85 Mon Sep 17 00:00:00 2001 From: tophf Date: Tue, 24 Nov 2020 15:16:29 +0300 Subject: [PATCH] monkeypatch next/prevBookmark commands to use jumpToPos --- edit/codemirror-factory.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/edit/codemirror-factory.js b/edit/codemirror-factory.js index 1639de47..74b26aee 100644 --- a/edit/codemirror-factory.js +++ b/edit/codemirror-factory.js @@ -405,6 +405,14 @@ const BRAND = 'sublimeBookmark'; const CLICK_AREA = 'CodeMirror-linenumbers'; const {markText} = CodeMirror.prototype; + for (const name of ['prevBookmark', 'nextBookmark']) { + const cmdFn = CodeMirror.commands[name]; + CodeMirror.commands[name] = cm => { + cm.setSelection = cm.jumpToPos; + cmdFn(cm); + delete cm.setSelection; + }; + } CodeMirror.defineInitHook(cm => { cm.on('gutterClick', onGutterClick); cm.on('gutterContextMenu', onGutterContextMenu); @@ -446,9 +454,7 @@ } function onGutterContextMenu(cm, line, name, e) { if (name === CLICK_AREA) { - cm.setSelection = cm.jumpToPos; cm.execCommand(e.ctrlKey ? 'prevBookmark' : 'nextBookmark'); - delete cm.setSelection; e.preventDefault(); } }