Changeset 148163 in webkit
- Timestamp:
- Apr 10, 2013 6:27:26 PM (11 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r148159 r148163 1 2013-04-10 Ryosuke Niwa <rniwa@webkit.org> 2 3 Cleanup local variables in Editor::markAndReplaceFor 4 https://bugs.webkit.org/show_bug.cgi?id=114383 5 6 Reviewed by Enrica Casucci. 7 8 Added resultEndLocation, which is the sum of resultLocation and resultLength. 9 10 Also replaced ambiguousBoundaryOffset by useAmbiguousBoundaryOffset since the ambiguous offset is always 11 selectionOffset -1 to avoid the extra house keeping and obnoxious -1 check. 12 13 * editing/Editor.cpp: 14 (WebCore::Editor::markAndReplaceFor): 15 1 16 2013-04-10 Benjamin Poulain <bpoulain@apple.com> 2 17 -
trunk/Source/WebCore/editing/Editor.cpp
r148124 r148163 2184 2184 const bool shouldShowCorrectionPanel = textCheckingOptions & TextCheckingTypeShowCorrectionPanel; 2185 2185 const bool shouldCheckForCorrection = shouldShowCorrectionPanel || (textCheckingOptions & TextCheckingTypeCorrection); 2186 #if !USE(AUTOCORRECTION_PANEL) 2187 ASSERT(!shouldShowCorrectionPanel); 2188 #endif 2186 2189 2187 2190 // Expand the range to encompass entire paragraphs, since text checking needs that much context. 2188 2191 int selectionOffset = 0; 2189 int ambiguousBoundaryOffset = -1;2192 bool useAmbiguousBoundaryOffset = false; 2190 2193 bool selectionChanged = false; 2191 2194 bool restoreSelectionAfterChange = false; … … 2201 2204 adjustSelectionForParagraphBoundaries = true; 2202 2205 if (selectionOffset > 0 && selectionOffset <= paragraph.textLength() && isAmbiguousBoundaryCharacter(paragraph.textCharAt(selectionOffset - 1))) 2203 ambiguousBoundaryOffset = selectionOffset - 1;2206 useAmbiguousBoundaryOffset = true; 2204 2207 } 2205 2208 } … … 2212 2215 const int resultLocation = results[i].location + offsetDueToReplacement; 2213 2216 const int resultLength = results[i].length; 2217 const int resultEndLocation = resultLocation + resultLength; 2214 2218 const String& replacement = results[i].replacement; 2215 const bool resultEndsAtAmbiguousBoundary = ambiguousBoundaryOffset >= 0 && resultLocation + resultLength == ambiguousBoundaryOffset;2219 const bool resultEndsAtAmbiguousBoundary = useAmbiguousBoundaryOffset && resultEndLocation == selectionOffset - 1; 2216 2220 2217 2221 // Only mark misspelling if: … … 2221 2225 // "wouldn'" as misspelled right after apostrophe is typed. 2222 2226 if (shouldMarkSpelling && !shouldShowCorrectionPanel && resultType == TextCheckingTypeSpelling 2223 && resultLocation >= paragraph.checkingStart() && result Location + resultLength<= spellingRangeEndOffset && !resultEndsAtAmbiguousBoundary) {2227 && resultLocation >= paragraph.checkingStart() && resultEndLocation <= spellingRangeEndOffset && !resultEndsAtAmbiguousBoundary) { 2224 2228 ASSERT(resultLength > 0 && resultLocation >= 0); 2225 2229 RefPtr<Range> misspellingRange = paragraph.subrange(resultLocation, resultLength); … … 2238 2242 } 2239 2243 } 2240 } else if (result Location + resultLength <= spellingRangeEndOffset && resultLocation + resultLength>= paragraph.checkingStart()2244 } else if (resultEndLocation <= spellingRangeEndOffset && resultEndLocation >= paragraph.checkingStart() 2241 2245 && isAutomaticTextReplacementType(resultType)) { 2242 2246 // In this case the result range just has to touch the spelling range, so we can handle replacing non-word text such as punctuation. 2243 2247 ASSERT(resultLength > 0 && resultLocation >= 0); 2244 2248 2245 if (shouldShowCorrectionPanel && (result Location + resultLength< spellingRangeEndOffset || resultType != TextCheckingTypeCorrection))2249 if (shouldShowCorrectionPanel && (resultEndLocation < spellingRangeEndOffset || resultType != TextCheckingTypeCorrection)) 2246 2250 continue; 2247 2251 … … 2254 2258 2255 2259 // adding links should be done only immediately after they are typed 2256 int resultEnd = resultLocation + resultLength; 2257 if (resultType == TextCheckingTypeLink 2258 && (selectionOffset > resultEnd + 1 || selectionOffset <= resultLocation)) 2260 if (resultType == TextCheckingTypeLink && (selectionOffset > resultEndLocation + 1 || selectionOffset <= resultLocation)) 2259 2261 continue; 2260 2262 … … 2268 2270 2269 2271 if (shouldShowCorrectionPanel) { 2270 #if !USE(AUTOCORRECTION_PANEL) 2271 ASSERT_NOT_REACHED(); 2272 #endif 2273 // shouldShowCorrectionPanel can be true only when the panel is available. 2274 if (resultLocation + resultLength == spellingRangeEndOffset) { 2272 if (resultEndLocation == spellingRangeEndOffset) { 2275 2273 // We only show the correction panel on the last word. 2276 2274 m_alternativeTextController->show(rangeToReplace, replacement); … … 2303 2301 selectionChanged = true; 2304 2302 offsetDueToReplacement += replacement.length() - resultLength; 2305 if (resultLocation < selectionOffset) {2303 if (resultLocation < selectionOffset) 2306 2304 selectionOffset += replacement.length() - resultLength; 2307 if (ambiguousBoundaryOffset >= 0)2308 ambiguousBoundaryOffset = selectionOffset - 1;2309 }2310 2305 2311 2306 // Add a marker so that corrections can easily be undone and won't be re-corrected.
Note: See TracChangeset
for help on using the changeset viewer.