Changeset 140828 in webkit
- Timestamp:
- Jan 25, 2013 8:22:00 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r140827 r140828 1 2013-01-25 Andrey Lushnikov <lushnikov@chromium.org> 2 3 Web Inspector: highlight occurences of word in DefaultTextEditor 4 https://bugs.webkit.org/show_bug.cgi?id=105523 5 6 Reviewed by Pavel Feldman. 7 8 Add new test to verify token highlightning functionality. 9 10 * inspector/editor/editor-test.js: 11 (initialize_EditorTests.InspectorTest.createTestEditor): Added optional TextEditorDelegate argument. 12 * inspector/editor/text-editor-highlight-token-expected.txt: Added. 13 * inspector/editor/text-editor-highlight-token.html: Added. 14 1 15 2013-01-25 Zan Dobersek <zdobersek@igalia.com> 2 16 -
trunk/LayoutTests/inspector/editor/editor-test.js
r139881 r140828 2 2 { 3 3 4 InspectorTest.createTestEditor = function(clientHeight, chunkSize )4 InspectorTest.createTestEditor = function(clientHeight, chunkSize, textEditorDelegate) 5 5 { 6 6 WebInspector.debugDefaultTextEditor = true; 7 var textEditor = new WebInspector.DefaultTextEditor("", new WebInspector.TextEditorDelegate());7 var textEditor = new WebInspector.DefaultTextEditor("", textEditorDelegate || new WebInspector.TextEditorDelegate()); 8 8 textEditor.overrideViewportForTest(0, clientHeight || 100, chunkSize || 10); 9 9 textEditor.show(WebInspector.inspectorView.element); -
trunk/Source/WebCore/ChangeLog
r140825 r140828 1 2013-01-25 Andrey Lushnikov <lushnikov@chromium.org> 2 3 Web Inspector: highlight occurences of word in DefaultTextEditor 4 https://bugs.webkit.org/show_bug.cgi?id=105523 5 6 Reviewed by Pavel Feldman. 7 8 Highlight occurrences of selected word in DefaultTextEditor by the means of new highlight regex API. 9 10 Test: inspector/editor/text-editor-highlight-token.html 11 12 * inspector/front-end/DefaultTextEditor.js: 13 (WebInspector.TextEditorMainPanel): 14 (WebInspector.TextEditorMainPanel.prototype._handleSelectionChange): 15 (WebInspector.TextEditorMainPanel.TokenHighlighter): Added. 16 (WebInspector.TextEditorMainPanel.TokenHighlighter.prototype.handleSelectionChange): 17 (WebInspector.TextEditorMainPanel.TokenHighlighter.prototype._regexString): 18 (WebInspector.TextEditorMainPanel.TokenHighlighter.prototype._highlight): 19 (WebInspector.TextEditorMainPanel.TokenHighlighter.prototype._removeHighlight): 20 (WebInspector.TextEditorMainPanel.TokenHighlighter.prototype._isWord): 21 * inspector/front-end/textEditor.css: 22 (.text-editor-token-highlight): 23 1 24 2013-01-25 Alexander Paschenko <alexander.pashenko@lge.com> 2 25 -
trunk/Source/WebCore/inspector/front-end/DefaultTextEditor.js
r140691 r140828 1363 1363 this._highlightRegexs = {}; 1364 1364 1365 this._tokenHighlighter = new WebInspector.TextEditorMainPanel.TokenHighlighter(this, textModel); 1366 1365 1367 this._freeCachedElements(); 1366 1368 this.buildChunks(); … … 2623 2625 if (textRange) 2624 2626 this._lastSelection = textRange; 2627 2628 this._tokenHighlighter.handleSelectionChange(textRange); 2625 2629 this._delegate.selectionChanged(textRange); 2626 2630 }, … … 2945 2949 } 2946 2950 2951 /** 2952 * @constructor 2953 * @param {WebInspector.TextEditorMainPanel} mainPanel 2954 * @param {WebInspector.TextEditorModel} textModel 2955 */ 2956 WebInspector.TextEditorMainPanel.TokenHighlighter = function(mainPanel, textModel) 2957 { 2958 this._mainPanel = mainPanel; 2959 this._textModel = textModel; 2960 } 2961 2962 WebInspector.TextEditorMainPanel.TokenHighlighter._NonWordCharRegex = /[^a-zA-Z0-9_]/; 2963 WebInspector.TextEditorMainPanel.TokenHighlighter._WordRegex = /^[a-zA-Z0-9_]+$/; 2964 2965 WebInspector.TextEditorMainPanel.TokenHighlighter.prototype = { 2966 /** 2967 * @param {WebInspector.TextRange} range 2968 */ 2969 handleSelectionChange: function(range) 2970 { 2971 if (!range) { 2972 this._removeHighlight(); 2973 return; 2974 } 2975 2976 if (range.startLine !== range.endLine) { 2977 this._removeHighlight(); 2978 return; 2979 } 2980 2981 range = range.normalize(); 2982 var selectedText = this._textModel.copyRange(range); 2983 if (selectedText === this._selectedWord) 2984 return; 2985 2986 if (selectedText === "") { 2987 this._removeHighlight(); 2988 return; 2989 } 2990 2991 if (this._isWord(range, selectedText)) 2992 this._highlight(selectedText); 2993 else 2994 this._removeHighlight(); 2995 }, 2996 2997 /** 2998 * @param {string} word 2999 */ 3000 _regexString: function(word) 3001 { 3002 return "\\b" + word + "\\b"; 3003 }, 3004 3005 /** 3006 * @param {string} selectedWord 3007 */ 3008 _highlight: function(selectedWord) 3009 { 3010 this._removeHighlight(); 3011 this._selectedWord = selectedWord; 3012 this._mainPanel.highlightRegex(this._regexString(selectedWord), "text-editor-token-highlight") 3013 }, 3014 3015 _removeHighlight: function() 3016 { 3017 if (this._selectedWord) { 3018 this._mainPanel.removeRegexHighlight(this._regexString(this._selectedWord)); 3019 delete this._selectedWord; 3020 } 3021 }, 3022 3023 /** 3024 * @param {WebInspector.TextRange} range 3025 * @param {string} selectedText 3026 * @return {boolean} 3027 */ 3028 _isWord: function(range, selectedText) 3029 { 3030 const NonWordChar = WebInspector.TextEditorMainPanel.TokenHighlighter._NonWordCharRegex; 3031 const WordRegex = WebInspector.TextEditorMainPanel.TokenHighlighter._WordRegex; 3032 var line = this._textModel.line(range.startLine); 3033 var leftBound = range.startColumn === 0 || NonWordChar.test(line.charAt(range.startColumn - 1)); 3034 var rightBound = range.endColumn === line.length - 1 || NonWordChar.test(line.charAt(range.endColumn)); 3035 return leftBound && rightBound && WordRegex.test(selectedText); 3036 } 3037 } 3038 2947 3039 WebInspector.debugDefaultTextEditor = false; -
trunk/Source/WebCore/inspector/front-end/textEditor.css
r139980 r140828 36 36 -webkit-user-select: none; 37 37 z-index: -1; 38 } 39 40 .text-editor-token-highlight { 41 -webkit-border-radius: 3px; 42 border: 1px solid gray; 38 43 } 39 44
Note: See TracChangeset
for help on using the changeset viewer.