Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(831)

Side by Side Diff: Source/devtools/front_end/CodeMirrorTextEditor.js

Issue 220203007: DevTools: fix primary selection in multiple selections created with ctrl-d (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 1127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 */ 1138 */
1139 setSelection: function(textRange) 1139 setSelection: function(textRange)
1140 { 1140 {
1141 this._lastSelection = textRange; 1141 this._lastSelection = textRange;
1142 var pos = this._toPos(textRange); 1142 var pos = this._toPos(textRange);
1143 this._codeMirror.setSelection(pos.start, pos.end); 1143 this._codeMirror.setSelection(pos.start, pos.end);
1144 }, 1144 },
1145 1145
1146 /** 1146 /**
1147 * @param {!Array.<!WebInspector.TextRange>} ranges 1147 * @param {!Array.<!WebInspector.TextRange>} ranges
1148 * @param {number=} primarySelectionIndex
1148 */ 1149 */
1149 setSelections: function(ranges) 1150 setSelections: function(ranges, primarySelectionIndex)
1150 { 1151 {
1151 var selections = []; 1152 var selections = [];
1152 for (var i = 0; i < ranges.length; ++i) { 1153 for (var i = 0; i < ranges.length; ++i) {
1153 var selection = this._toPos(ranges[i]); 1154 var selection = this._toPos(ranges[i]);
1154 selections.push({ 1155 selections.push({
1155 anchor: selection.start, 1156 anchor: selection.start,
1156 head: selection.end 1157 head: selection.end
1157 }); 1158 });
1158 } 1159 }
1159 this._codeMirror.setSelections(selections, 0, { scroll: false }); 1160 primarySelectionIndex = primarySelectionIndex || 0;
1161 this._codeMirror.setSelections(selections, primarySelectionIndex, { scro ll: false });
1160 }, 1162 },
1161 1163
1162 /** 1164 /**
1163 * @param {string} text 1165 * @param {string} text
1164 */ 1166 */
1165 _detectLineSeparator: function(text) 1167 _detectLineSeparator: function(text)
1166 { 1168 {
1167 this._lineSeparator = text.indexOf("\r\n") >= 0 ? "\r\n" : "\n"; 1169 this._lineSeparator = text.indexOf("\r\n") >= 0 ? "\r\n" : "\n";
1168 }, 1170 },
1169 1171
(...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after
1829 var next = last; 1831 var next = last;
1830 do { 1832 do {
1831 next = this._findNextOccurrence(next, !!this._fullWordSelection); 1833 next = this._findNextOccurrence(next, !!this._fullWordSelection);
1832 } while (next && this._findRange(selections, next) && !next.equal(last)) ; 1834 } while (next && this._findRange(selections, next) && !next.equal(last)) ;
1833 1835
1834 if (!next) 1836 if (!next)
1835 return; 1837 return;
1836 selections.push(next); 1838 selections.push(next);
1837 1839
1838 this._muteSelectionListener = true; 1840 this._muteSelectionListener = true;
1839 this._textEditor.setSelections(selections); 1841 this._textEditor.setSelections(selections, selections.length - 1);
1840 delete this._muteSelectionListener; 1842 delete this._muteSelectionListener;
1841 1843
1842 this._textEditor._revealLine(next.startLine); 1844 this._textEditor._revealLine(next.startLine);
1843 }, 1845 },
1844 1846
1845 /** 1847 /**
1846 * @param {!Array.<!WebInspector.TextRange>} selections 1848 * @param {!Array.<!WebInspector.TextRange>} selections
1847 */ 1849 */
1848 _expandSelectionsToWords: function(selections) 1850 _expandSelectionsToWords: function(selections)
1849 { 1851 {
1850 var newSelections = []; 1852 var newSelections = [];
1851 for (var i = 0; i < selections.length; ++i) { 1853 for (var i = 0; i < selections.length; ++i) {
1852 var selection = selections[i]; 1854 var selection = selections[i];
1853 var startRangeWord = this._textEditor._wordRangeForCursorPosition(se lection.startLine, selection.startColumn) 1855 var startRangeWord = this._textEditor._wordRangeForCursorPosition(se lection.startLine, selection.startColumn)
1854 || WebInspector.TextRange.createFromLocation(selection.startLine , selection.startColumn); 1856 || WebInspector.TextRange.createFromLocation(selection.startLine , selection.startColumn);
1855 var endRangeWord = this._textEditor._wordRangeForCursorPosition(sele ction.endLine, selection.endColumn) 1857 var endRangeWord = this._textEditor._wordRangeForCursorPosition(sele ction.endLine, selection.endColumn)
1856 || WebInspector.TextRange.createFromLocation(selection.endLine, selection.endColumn); 1858 || WebInspector.TextRange.createFromLocation(selection.endLine, selection.endColumn);
1857 var newSelection = new WebInspector.TextRange(startRangeWord.startLi ne, startRangeWord.startColumn, endRangeWord.endLine, endRangeWord.endColumn); 1859 var newSelection = new WebInspector.TextRange(startRangeWord.startLi ne, startRangeWord.startColumn, endRangeWord.endLine, endRangeWord.endColumn);
1858 newSelections.push(newSelection); 1860 newSelections.push(newSelection);
1859 } 1861 }
1860 this._textEditor.setSelections(newSelections); 1862 this._textEditor.setSelections(newSelections, newSelections.length - 1);
1861 this._fullWordSelection = true; 1863 this._fullWordSelection = true;
1862 }, 1864 },
1863 1865
1864 /** 1866 /**
1865 * @param {!WebInspector.TextRange} range 1867 * @param {!WebInspector.TextRange} range
1866 * @param {boolean} fullWord 1868 * @param {boolean} fullWord
1867 * @return {?WebInspector.TextRange} 1869 * @return {?WebInspector.TextRange}
1868 */ 1870 */
1869 _findNextOccurrence: function(range, fullWord) 1871 _findNextOccurrence: function(range, fullWord)
1870 { 1872 {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 var backgroundColorRule = backgroundColor ? ".CodeMirror .CodeMirror-selecte d { background-color: " + backgroundColor + ";}" : ""; 1954 var backgroundColorRule = backgroundColor ? ".CodeMirror .CodeMirror-selecte d { background-color: " + backgroundColor + ";}" : "";
1953 var foregroundColor = InspectorFrontendHost.getSelectionForegroundColor(); 1955 var foregroundColor = InspectorFrontendHost.getSelectionForegroundColor();
1954 var foregroundColorRule = foregroundColor ? ".CodeMirror .CodeMirror-selecte dtext:not(.CodeMirror-persist-highlight) { color: " + foregroundColor + "!import ant;}" : ""; 1956 var foregroundColorRule = foregroundColor ? ".CodeMirror .CodeMirror-selecte dtext:not(.CodeMirror-persist-highlight) { color: " + foregroundColor + "!import ant;}" : "";
1955 if (!foregroundColorRule && !backgroundColorRule) 1957 if (!foregroundColorRule && !backgroundColorRule)
1956 return; 1958 return;
1957 1959
1958 var style = document.createElement("style"); 1960 var style = document.createElement("style");
1959 style.textContent = backgroundColorRule + foregroundColorRule; 1961 style.textContent = backgroundColorRule + foregroundColorRule;
1960 document.head.appendChild(style); 1962 document.head.appendChild(style);
1961 })(); 1963 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698