diff options
author | seenxu <seen_xu@msn.com> | 2020-12-30 22:15:50 +0100 |
---|---|---|
committer | Jack Rosenthal <jack@rosenth.al> | 2021-01-06 16:47:14 -0700 |
commit | 729122416f551c0b1031ca0c0968148a4600d422 (patch) | |
tree | 4094f638db607d6ea9e57ff3cc2806b9cdc6824a | |
parent | 4749f95d1ce07f95cd64bb028e9f9fdd1f7f6bd0 (diff) | |
download | pentadactyl-729122416f551c0b1031ca0c0968148a4600d422.tar.gz |
issue #9, mark matched selection in highlighted text field
-rw-r--r-- | common/modules/finder.jsm | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/common/modules/finder.jsm b/common/modules/finder.jsm index e21e3348..9217c788 100644 --- a/common/modules/finder.jsm +++ b/common/modules/finder.jsm @@ -405,18 +405,40 @@ var RangeFind = Class("RangeFind", { get flags() { return this.matchCase ? "" : "i"; }, get selectedRange() { - let win = this.store.focusedFrame && this.store.focusedFrame.get() || this.content; - + let win = this.store.focusedFrame && this.store.focusedFrame.get( + ) || this.content; let selection = win.getSelection(); - return (selection.rangeCount ? selection.getRangeAt(0) : this.ranges[0].range).cloneRange(); + let range = null; + if (selection.rangeCount) { + range = selection.getRangeAt(0); + this.show_selection_in_editing_node(range, false); + } else { + range = this.ranges[0].range; + } + return range.cloneRange(); }, set selectedRange(range) { this.range.selection.removeAllRanges(); this.range.selection.addRange(range); this.range.selectionController.scrollSelectionIntoView( this.range.selectionController.SELECTION_NORMAL, 0, false); - - this.store.focusedFrame = util.weakReference(range.startContainer.ownerDocument.defaultView); + this.show_selection_in_editing_node(range, true); + this.store.focusedFrame = util.weakReference( + range.startContainer.ownerDocument.defaultView); + }, + + show_selection_in_editing_node: function(range, is_selected) { + for (let node = range.startContainer; node; node = node.parentNode) { + if (node instanceof Ci.nsIDOMNSEditableElement) { + let sel = node.editor.selectionController.getSelection( + Ci.nsISelectionController.SELECTION_IME_SELECTEDRAWTEXT); + sel.removeAllRanges(); + if (is_selected) { + sel.addRange(range); + } + break; + } + } }, cancel: function cancel() { |