Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 187f5fc

Browse files
committed
Merge pull request #7775 from adobe/nj/issue-7764
Make getModeForRange() behave like getModeForSelection() when mode is not mixed
2 parents 6014714 + 06d97f1 commit 187f5fc

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/editor/Editor.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1869,14 +1869,20 @@ define(function (require, exports, module) {
18691869
*
18701870
* @param {!{line: number, ch: number}} start The start of the range to check.
18711871
* @param {!{line: number, ch: number}} end The end of the range to check.
1872+
* @param {boolean=} knownMixed Whether we already know we're in a mixed mode and need to check both
1873+
* the start and end.
18721874
* @return {?(Object|string)} Name of syntax-highlighting mode, or object containing a "name" property
18731875
* naming the mode along with configuration options required by the mode.
18741876
* See {@link LanguageManager#getLanguageForPath()} and {@link Language#getMode()}.
18751877
*/
1876-
Editor.prototype.getModeForRange = function (start, end) {
1877-
var startMode = TokenUtils.getModeAt(this._codeMirror, start),
1878+
Editor.prototype.getModeForRange = function (start, end, knownMixed) {
1879+
var outerMode = this._codeMirror.getMode(),
1880+
startMode = TokenUtils.getModeAt(this._codeMirror, start),
18781881
endMode = TokenUtils.getModeAt(this._codeMirror, end);
1879-
if (!startMode || !endMode || startMode.name !== endMode.name) {
1882+
if (!knownMixed && outerMode.name === startMode.name) {
1883+
// Mode does not vary: just use the editor-wide mode name
1884+
return this._codeMirror.getOption("mode");
1885+
} else if (!startMode || !endMode || startMode.name !== endMode.name) {
18801886
return null;
18811887
} else {
18821888
return startMode;
@@ -1921,7 +1927,7 @@ define(function (require, exports, module) {
19211927
return false;
19221928
}
19231929

1924-
var rangeMode = self.getModeForRange(sel.start, sel.end);
1930+
var rangeMode = self.getModeForRange(sel.start, sel.end, true);
19251931
return (!rangeMode || rangeMode.name !== startMode.name);
19261932
});
19271933
if (hasMixedSel) {

0 commit comments

Comments
 (0)