Skip to content

Commit

Permalink
On left/right keydown place edit_point correctly when there is a sele…
Browse files Browse the repository at this point in the history
…ction in TextInput

Fixes #4447
  • Loading branch information
ema-fox committed Dec 21, 2014
1 parent a773bd5 commit c732a77
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions components/script/textinput.rs
Expand Up @@ -97,15 +97,20 @@ impl TextInput {
self.replace_selection(ch.to_string());
}

fn replace_selection(&mut self, insert: String) {
let begin = self.selection_begin.take().unwrap();
fn get_sorted_selection(&self) -> (TextPoint, TextPoint) {
let begin = self.selection_begin.unwrap();
let end = self.edit_point;

let (begin, end) = if begin.line < end.line || (begin.line == end.line && begin.index < end.index) {
if begin.line < end.line || (begin.line == end.line && begin.index < end.index) {
(begin, end)
} else {
(end, begin)
};
}
}

fn replace_selection(&mut self, insert: String) {
let (begin, end) = self.get_sorted_selection();
self.selection_begin = None;

let new_lines = {
let prefix = self.lines[begin.line].slice_chars(0, begin.index);
Expand Down Expand Up @@ -186,7 +191,12 @@ impl TextInput {
self.selection_begin = Some(self.edit_point);
}
} else {
self.selection_begin = None;
if self.selection_begin.is_some() {
let (begin, end) = self.get_sorted_selection();
self.edit_point = if adjust < 0 {begin} else {end};
self.selection_begin = None;
return
}
}

if adjust < 0 {
Expand Down

5 comments on commit c732a77

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from jdm
at ema-fox@c732a77

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging ema-fox/servo/textinput_selection = c732a77 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ema-fox/servo/textinput_selection = c732a77 merged ok, testing candidate = bde6c39

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = bde6c39

Please sign in to comment.