Commit 147de161 authored by sergio@webkit.org's avatar sergio@webkit.org

Inserting a blank (" ") at the end of a line does not insert anything in Overtype mode

https://bugs.webkit.org/show_bug.cgi?id=113413

Reviewed by Ryosuke Niwa.

Source/WebCore:

Perform a "normal" insert instead of a replace when there is
nothing to replace (like at the end of a line) as this case is not
supported by the replacing code path. This will allow us to
properly rebalance whitespaces in those cases.

Updated the editing/execCommand/overtype.html test to check also
this use case.

* editing/InsertTextCommand.cpp:
(WebCore::InsertTextCommand::setEndingSelectionWithoutValidation):
(WebCore::InsertTextCommand::performTrivialReplace):
(WebCore::InsertTextCommand::performOverwrite):
(WebCore::InsertTextCommand::doApply): use the recently added
setEndingSelectionWithoutValidation() to avoid code duplication.
* editing/InsertTextCommand.h:
(InsertTextCommand):

LayoutTests:

Updated the test to include the case of inserting a whitespace
both in the middle or at the end of a line.

* editing/execCommand/overtype-expected.txt:
* editing/execCommand/overtype.html:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@146999 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent dd1d9f54
2013-03-27 Sergio Villar Senin <svillar@igalia.com>
Inserting a blank (" ") at the end of a line does not insert anything in Overtype mode
https://bugs.webkit.org/show_bug.cgi?id=113413
Reviewed by Ryosuke Niwa.
Updated the test to include the case of inserting a whitespace
both in the middle or at the end of a line.
* editing/execCommand/overtype-expected.txt:
* editing/execCommand/overtype.html:
2013-03-27 Zan Dobersek <zdobersek@igalia.com>
Unreviewed GTK gardening.
......@@ -13,11 +13,11 @@ These are the original contents:
| "
"
After overwritting the first two characters:
After overwritting the first character:
| "
"
| <b>
| "FO<#selection-caret>o"
| "F<#selection-caret>oo"
| <a>
| href="http://www.google.com/"
| <div>
......@@ -30,7 +30,20 @@ After inserting a blank:
| "
"
| <b>
| "FO<#selection-caret> "
| "F <#selection-caret>o"
| <a>
| href="http://www.google.com/"
| <div>
| id="linkText"
| "bar"
| "
"
After inserting a blank at the line end:
| "
"
| <b>
| "F o <#selection-caret>"
| <a>
| href="http://www.google.com/"
| <div>
......@@ -43,7 +56,7 @@ Overwrite at the end of a line performs as a normal Insert:
| "
"
| <b>
| "FOO SOME MORE<#selection-caret>"
| "F o SOME MORE<#selection-caret>"
| <a>
| href="http://www.google.com/"
| <div>
......@@ -56,7 +69,7 @@ Overwritting works even if the inserted text is longer than the replaced text:
| "
"
| <b>
| "FOO SOME MORE"
| "F o SOME MORE"
| <a>
| href="http://www.google.com/"
| <div>
......@@ -69,7 +82,7 @@ Overwrite should create new text nodes on demand:
| "
"
| <b>
| "FOO SOME MORE"
| "F o SOME MORE"
| <div>
| id="linkText"
| <a>
......
......@@ -29,13 +29,17 @@ else {
selection.collapse(element, 0);
internals.toggleOverwriteModeEnabled(document);
document.execCommand("InsertText", false, 'FO');
Markup.dump(element, 'After overwritting the first two characters');
document.execCommand("InsertText", false, 'F');
Markup.dump(element, 'After overwritting the first character');
document.execCommand("InsertText", false, ' ');
Markup.dump(element, 'After inserting a blank');
document.execCommand("InsertText", false, 'O SOME MORE');
moveSelectionForwardByCharacterCommand();
document.execCommand("InsertText", false, ' ');
Markup.dump(element, 'After inserting a blank at the line end');
document.execCommand("InsertText", false, 'SOME MORE');
Markup.dump(element, 'Overwrite at the end of a line performs as a normal Insert');
selection.collapse(document.getElementById("linkText"), 0);
......
2013-03-27 Sergio Villar Senin <svillar@igalia.com>
Inserting a blank (" ") at the end of a line does not insert anything in Overtype mode
https://bugs.webkit.org/show_bug.cgi?id=113413
Reviewed by Ryosuke Niwa.
Perform a "normal" insert instead of a replace when there is
nothing to replace (like at the end of a line) as this case is not
supported by the replacing code path. This will allow us to
properly rebalance whitespaces in those cases.
Updated the editing/execCommand/overtype.html test to check also
this use case.
* editing/InsertTextCommand.cpp:
(WebCore::InsertTextCommand::setEndingSelectionWithoutValidation):
(WebCore::InsertTextCommand::performTrivialReplace):
(WebCore::InsertTextCommand::performOverwrite):
(WebCore::InsertTextCommand::doApply): use the recently added
setEndingSelectionWithoutValidation() to avoid code duplication.
* editing/InsertTextCommand.h:
(InsertTextCommand):
2013-03-27 Dean Jackson <dino@apple.com>
[Mac] Use fontName rather than familyName for internal fonts
......@@ -75,7 +75,7 @@ Position InsertTextCommand::positionInsideTextNode(const Position& p)
return pos;
}
void InsertTextCommand::setEndingSelectionWithoutValidation(const Position& startPosition, const Position& endPosition, bool selectInsertedText)
void InsertTextCommand::setEndingSelectionWithoutValidation(const Position& startPosition, const Position& endPosition)
{
// We could have inserted a part of composed character sequence,
// so we are basically treating ending selection as a range to avoid validation.
......@@ -84,9 +84,6 @@ void InsertTextCommand::setEndingSelectionWithoutValidation(const Position& star
forcedEndingSelection.setWithoutValidation(startPosition, endPosition);
forcedEndingSelection.setIsDirectional(endingSelection().isDirectional());
setEndingSelection(forcedEndingSelection);
if (!selectInsertedText)
setEndingSelection(VisibleSelection(endingSelection().visibleEnd(), endingSelection().isDirectional()));
}
// This avoids the expense of a full fledged delete operation, and avoids a layout that typically results
......@@ -104,7 +101,9 @@ bool InsertTextCommand::performTrivialReplace(const String& text, bool selectIns
if (endPosition.isNull())
return false;
setEndingSelectionWithoutValidation(start, endPosition, selectInsertedText);
setEndingSelectionWithoutValidation(start, endPosition);
if (!selectInsertedText)
setEndingSelection(VisibleSelection(endingSelection().visibleEnd(), endingSelection().isDirectional()));
return true;
}
......@@ -117,10 +116,15 @@ bool InsertTextCommand::performOverwrite(const String& text, bool selectInserted
return false;
unsigned count = std::min(text.length(), textNode->length() - start.offsetInContainerNode());
if (!count)
return false;
replaceTextInNode(textNode, start.offsetInContainerNode(), count, text);
Position endPosition = Position(textNode.release(), start.offsetInContainerNode() + text.length());
setEndingSelectionWithoutValidation(start, endPosition, selectInsertedText);
setEndingSelectionWithoutValidation(start, endPosition);
if (!selectInsertedText)
setEndingSelection(VisibleSelection(endingSelection().visibleEnd(), endingSelection().isDirectional()));
return true;
}
......@@ -216,13 +220,7 @@ void InsertTextCommand::doApply()
}
}
// We could have inserted a part of composed character sequence,
// so we are basically treating ending selection as a range to avoid validation.
// <http://bugs.webkit.org/show_bug.cgi?id=15781>
VisibleSelection forcedEndingSelection;
forcedEndingSelection.setWithoutValidation(startPosition, endPosition);
forcedEndingSelection.setIsDirectional(endingSelection().isDirectional());
setEndingSelection(forcedEndingSelection);
setEndingSelectionWithoutValidation(startPosition, endPosition);
// Handle the case where there is a typing style.
if (RefPtr<EditingStyle> typingStyle = document()->frame()->selection()->typingStyle()) {
......
......@@ -73,7 +73,7 @@ private:
bool performTrivialReplace(const String&, bool selectInsertedText);
bool performOverwrite(const String&, bool selectInsertedText);
void setEndingSelectionWithoutValidation(const Position& startPosition, const Position& endPosition, bool selectInsertedText);
void setEndingSelectionWithoutValidation(const Position& startPosition, const Position& endPosition);
friend class TypingCommand;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment