From 451b392034a54c4aef45f50aec9302df753a85ad Mon Sep 17 00:00:00 2001 From: tophf Date: Sun, 29 Mar 2015 17:02:06 +0300 Subject: [PATCH] Editor: when in applies-to, use its code box for search --- edit.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/edit.js b/edit.js index 855be306..690f937f 100644 --- a/edit.js +++ b/edit.js @@ -468,7 +468,7 @@ function setupGlobalSearch() { findNext(cm, true); } - function getVisibleEditor() { + function getVisibleEditor(activeElement) { var linesVisible = 2; // closest editor should have at least # lines visible function getScrollDistance(cm) { var bounds = cm.display.wrapper.parentNode.getBoundingClientRect(); @@ -480,6 +480,17 @@ function setupGlobalSearch() { return bounds.top - bounds.height; } } + if (activeElement && activeElement.className.indexOf("applies-") >= 0) { + for (var section = activeElement; section.parentNode; section = section.parentNode) { + var cmWrapper = section.querySelector(".CodeMirror"); + if (cmWrapper) { + if (getScrollDistance(cmWrapper.CodeMirror) == 0) { + return cmWrapper.CodeMirror; + } + break; + } + } + } if (editors.lastActive && getScrollDistance(editors.lastActive) == 0) { return editors.lastActive; } @@ -498,7 +509,7 @@ function setupGlobalSearch() { event.preventDefault(); event.stopPropagation(); if (!event.target.classList.contains("CodeMirror-search-field")) { - CodeMirror.commands[command](getVisibleEditor()); + CodeMirror.commands[command](getVisibleEditor(event.target)); } }