From e44af458c0c06b7a3899c234ce2e503e0cef0dda Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Tue, 4 Aug 2020 10:14:38 -0400 Subject: [PATCH] Fine tune visuals of CodeMirror's search feature Added a dotted box around found text occurrences, as just pale yellow to highlight the text is not enough to visually distinguish from surrounding text. Iterating through found text occurrences will now ensure they are vertically positioned in the middle of the editor. --- src/css/codemirror.css | 3 +++ src/js/codemirror/search.js | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/css/codemirror.css b/src/css/codemirror.css index 7f1668c57..3b7c1f20e 100644 --- a/src/css/codemirror.css +++ b/src/css/codemirror.css @@ -105,6 +105,9 @@ div.CodeMirror span.CodeMirror-matchingbracket { .cm-search-widget .sourceURL[href=""] { display: none; } +.cm-searching { + border: 1px dotted black; + } .CodeMirror-merge-l-deleted { background-image: none; diff --git a/src/js/codemirror/search.js b/src/js/codemirror/search.js index 9da1b401c..125bd28b4 100644 --- a/src/js/codemirror/search.js +++ b/src/js/codemirror/search.js @@ -345,7 +345,11 @@ if (!cursor.find(previous)) return; } cm.setSelection(cursor.from(), cursor.to()); - cm.scrollIntoView({from: cursor.from(), to: cursor.to()}, 20); + const { clientHeight } = cm.getScrollInfo(); + cm.scrollIntoView( + { from: cursor.from(), to: cursor.to() }, + clientHeight >>> 1 + ); if (callback) callback(cursor.from(), cursor.to()); }); };