@@ -50,6 +50,12 @@ define(function (require, exports, module) {
5050 */
5151 var ZERO_FILES_TO_SEARCH = { } ;
5252
53+ /**
54+ * Maximum length of text displayed in search results panel
55+ * @const
56+ */
57+ var MAX_DISPLAY_LENGTH = 200 ;
58+
5359 /**
5460 * The search query and results model.
5561 * @type {SearchModel }
@@ -91,7 +97,8 @@ define(function (require, exports, module) {
9197 return [ ] ;
9298 }
9399
94- var match , lineNum , line , ch , totalMatchLength , matchedLines , numMatchedLines , lastLineLength ,
100+ var match , lineNum , line , ch , totalMatchLength , matchedLines , numMatchedLines , lastLineLength , endCh ,
101+ padding , leftPadding , rightPadding , highlightOffset , highlightEndCh ,
95102 lines = StringUtils . getLines ( contents ) ,
96103 matches = [ ] ;
97104
@@ -103,13 +110,31 @@ define(function (require, exports, module) {
103110 numMatchedLines = matchedLines . length ;
104111 totalMatchLength = match [ 0 ] . length ;
105112 lastLineLength = matchedLines [ matchedLines . length - 1 ] . length ;
113+ endCh = ( numMatchedLines === 1 ? ch + totalMatchLength : lastLineLength ) ;
114+ highlightEndCh = ( numMatchedLines === 1 ? endCh : line . length ) ;
115+ highlightOffset = 0 ;
106116
107- // Don't store more than 200 chars per line
108- line = line . substr ( 0 , Math . min ( 200 , line . length ) ) ;
117+ if ( highlightEndCh <= MAX_DISPLAY_LENGTH ) {
118+ // Don't store more than 200 chars per line
119+ line = line . substr ( 0 , Math . min ( MAX_DISPLAY_LENGTH , line . length ) ) ;
120+ } else if ( totalMatchLength > MAX_DISPLAY_LENGTH ) {
121+ // impossible to display the whole match
122+ line = line . substr ( ch , ch + MAX_DISPLAY_LENGTH ) ;
123+ highlightOffset = ch ;
124+ } else {
125+ // Try to have both beginning and end of match displayed
126+ padding = MAX_DISPLAY_LENGTH - totalMatchLength ;
127+ rightPadding = Math . floor ( Math . min ( padding / 2 , line . length - highlightEndCh ) ) ;
128+ leftPadding = Math . ceil ( padding - rightPadding ) ;
129+ highlightOffset = ch - leftPadding ;
130+ line = line . substring ( highlightOffset , highlightEndCh + rightPadding ) ;
131+ }
109132
110133 matches . push ( {
111134 start : { line : lineNum , ch : ch } ,
112- end : { line : lineNum + numMatchedLines - 1 , ch : ( numMatchedLines === 1 ? ch + totalMatchLength : lastLineLength ) } ,
135+ end : { line : lineNum + numMatchedLines - 1 , ch : endCh } ,
136+
137+ highlightOffset : highlightOffset ,
113138
114139 // Note that the following offsets from the beginning of the file are *not* updated if the search
115140 // results change. These are currently only used for multi-file replacement, and we always
0 commit comments