Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextInput: set_content sets wrong edit_point #4622

Closed
donaldpipowitch opened this issue Jan 13, 2015 · 0 comments · Fixed by #4648
Closed

TextInput: set_content sets wrong edit_point #4622

donaldpipowitch opened this issue Jan 13, 2015 · 0 comments · Fixed by #4648
Labels
A-content/editing User input related to text editing

Comments

@donaldpipowitch
Copy link
Contributor

In my ongoing pull request for unit test for TextInput it looks like the edit_point is wrong if set_content is used in some cases.

From #4569 (comment):

We have the String "abc\nf", make a selection of "abc", replace the content with "de" and edit_point.index will be 1. I would expect [...] 2 as the end of "de".

From https://github.com/donaldpipowitch/servo/blob/6ce72e60b70fa43f7006576a02465d64f7f8c997/components/script/textinput.rs#L492:

#[test]
fn test_textinput_set_content() {
    let mut textinput = TextInput::new(Lines::Multiple, "abc\nde\nf".into_string());
    assert_eq!(textinput.get_content().as_slice(), "abc\nde\nf");

    textinput.set_content("abc\nf".into_string());
    assert_eq!(textinput.get_content().as_slice(), "abc\nf");

    assert_eq!(textinput.edit_point.line, 0);
    assert_eq!(textinput.edit_point.index, 0);
    textinput.adjust_horizontal(3, true);
    assert_eq!(textinput.edit_point.line, 0);
    assert_eq!(textinput.edit_point.index, 3);
    textinput.set_content("de".into_string());
    assert_eq!(textinput.get_content().as_slice(), "de");
    assert_eq!(textinput.edit_point.line, 0);
    assert_eq!(textinput.edit_point.index, 1);
}
@jdm jdm added the A-content/editing User input related to text editing label Jan 13, 2015
bors-servo pushed a commit that referenced this issue Jan 18, 2015
Fixes #4622

Previously, when the edit point was being clamped leftward by a shortened
line, it would be placed one one character too far to the left instead of
at the very end.

The "if" removed here was introduced in f686943 to fix a crash, but the underlying reason for the crash was the incorrect "- 1", which has been there since the beginning ( 80764f6 ).
bors-servo pushed a commit that referenced this issue Jan 18, 2015
Fixes #4622

Previously, when the edit point was being clamped leftward by a shortened
line, it would be placed one one character too far to the left instead of
at the very end.

The "if" removed here was introduced in f686943 to fix a crash, but the underlying reason for the crash was the incorrect "- 1", which has been there since the beginning ( 80764f6 ).
bors-servo pushed a commit that referenced this issue Jan 18, 2015
Fixes #4622

Previously, when the edit point was being clamped leftward by a shortened
line, it would be placed one one character too far to the left instead of
at the very end.

The "if" removed here was introduced in f686943 to fix a crash, but the underlying reason for the crash was the incorrect "- 1", which has been there since the beginning ( 80764f6 ).
bors-servo pushed a commit that referenced this issue Jan 18, 2015
Fixes #4622

Previously, when the edit point was being clamped leftward by a shortened
line, it would be placed one one character too far to the left instead of
at the very end.

The "if" removed here was introduced in f686943 to fix a crash, but the underlying reason for the crash was the incorrect "- 1", which has been there since the beginning ( 80764f6 ).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-content/editing User input related to text editing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants