Rename _para to _paragraph

pull/1814/head
Ivan Tham 3 years ago committed by Blaž Hrastnik
parent 64c2490f2d
commit 8b91ecde40

@ -150,7 +150,12 @@ fn word_move(slice: RopeSlice, range: Range, count: usize, target: WordMotionTar
}) })
} }
pub fn move_prev_para(slice: RopeSlice, range: Range, count: usize, behavior: Movement) -> Range { pub fn move_prev_paragraph(
slice: RopeSlice,
range: Range,
count: usize,
behavior: Movement,
) -> Range {
let mut line = range.cursor_line(slice); let mut line = range.cursor_line(slice);
let first_char = slice.line_to_char(line) == range.cursor(slice); let first_char = slice.line_to_char(line) == range.cursor(slice);
let prev_line_empty = rope_is_line_ending(slice.line(line.saturating_sub(1))); let prev_line_empty = rope_is_line_ending(slice.line(line.saturating_sub(1)));
@ -187,7 +192,12 @@ pub fn move_prev_para(slice: RopeSlice, range: Range, count: usize, behavior: Mo
Range::new(anchor, head) Range::new(anchor, head)
} }
pub fn move_next_para(slice: RopeSlice, range: Range, count: usize, behavior: Movement) -> Range { pub fn move_next_paragraph(
slice: RopeSlice,
range: Range,
count: usize,
behavior: Movement,
) -> Range {
let mut line = range.cursor_line(slice); let mut line = range.cursor_line(slice);
let last_char = let last_char =
prev_grapheme_boundary(slice, slice.line_to_char(line + 1)) == range.cursor(slice); prev_grapheme_boundary(slice, slice.line_to_char(line + 1)) == range.cursor(slice);
@ -1280,7 +1290,7 @@ mod test {
let (s, selection) = crate::test::print(before); let (s, selection) = crate::test::print(before);
let text = Rope::from(s.as_str()); let text = Rope::from(s.as_str());
let selection = let selection =
selection.transform(|r| move_prev_para(text.slice(..), r, 1, Movement::Move)); selection.transform(|r| move_prev_paragraph(text.slice(..), r, 1, Movement::Move));
let actual = crate::test::plain(&s, selection); let actual = crate::test::plain(&s, selection);
assert_eq!(actual, expected, "\nbefore: `{before:?}`"); assert_eq!(actual, expected, "\nbefore: `{before:?}`");
} }
@ -1303,7 +1313,7 @@ mod test {
let (s, selection) = crate::test::print(before); let (s, selection) = crate::test::print(before);
let text = Rope::from(s.as_str()); let text = Rope::from(s.as_str());
let selection = let selection =
selection.transform(|r| move_prev_para(text.slice(..), r, 2, Movement::Move)); selection.transform(|r| move_prev_paragraph(text.slice(..), r, 2, Movement::Move));
let actual = crate::test::plain(&s, selection); let actual = crate::test::plain(&s, selection);
assert_eq!(actual, expected, "\nbefore: `{before:?}`"); assert_eq!(actual, expected, "\nbefore: `{before:?}`");
} }
@ -1325,8 +1335,8 @@ mod test {
for (before, expected) in tests { for (before, expected) in tests {
let (s, selection) = crate::test::print(before); let (s, selection) = crate::test::print(before);
let text = Rope::from(s.as_str()); let text = Rope::from(s.as_str());
let selection = let selection = selection
selection.transform(|r| move_prev_para(text.slice(..), r, 1, Movement::Extend)); .transform(|r| move_prev_paragraph(text.slice(..), r, 1, Movement::Extend));
let actual = crate::test::plain(&s, selection); let actual = crate::test::plain(&s, selection);
assert_eq!(actual, expected, "\nbefore: `{before:?}`"); assert_eq!(actual, expected, "\nbefore: `{before:?}`");
} }
@ -1360,7 +1370,7 @@ mod test {
let (s, selection) = crate::test::print(before); let (s, selection) = crate::test::print(before);
let text = Rope::from(s.as_str()); let text = Rope::from(s.as_str());
let selection = let selection =
selection.transform(|r| move_next_para(text.slice(..), r, 1, Movement::Move)); selection.transform(|r| move_next_paragraph(text.slice(..), r, 1, Movement::Move));
let actual = crate::test::plain(&s, selection); let actual = crate::test::plain(&s, selection);
assert_eq!(actual, expected, "\nbefore: `{before:?}`"); assert_eq!(actual, expected, "\nbefore: `{before:?}`");
} }
@ -1383,7 +1393,7 @@ mod test {
let (s, selection) = crate::test::print(before); let (s, selection) = crate::test::print(before);
let text = Rope::from(s.as_str()); let text = Rope::from(s.as_str());
let selection = let selection =
selection.transform(|r| move_next_para(text.slice(..), r, 2, Movement::Move)); selection.transform(|r| move_next_paragraph(text.slice(..), r, 2, Movement::Move));
let actual = crate::test::plain(&s, selection); let actual = crate::test::plain(&s, selection);
assert_eq!(actual, expected, "\nbefore: `{before:?}`"); assert_eq!(actual, expected, "\nbefore: `{before:?}`");
} }
@ -1405,8 +1415,8 @@ mod test {
for (before, expected) in tests { for (before, expected) in tests {
let (s, selection) = crate::test::print(before); let (s, selection) = crate::test::print(before);
let text = Rope::from(s.as_str()); let text = Rope::from(s.as_str());
let selection = let selection = selection
selection.transform(|r| move_next_para(text.slice(..), r, 1, Movement::Extend)); .transform(|r| move_next_paragraph(text.slice(..), r, 1, Movement::Extend));
let actual = crate::test::plain(&s, selection); let actual = crate::test::plain(&s, selection);
assert_eq!(actual, expected, "\nbefore: `{before:?}`"); assert_eq!(actual, expected, "\nbefore: `{before:?}`");
} }

@ -112,7 +112,7 @@ pub fn textobject_word(
} }
} }
pub fn textobject_para( pub fn textobject_paragraph(
slice: RopeSlice, slice: RopeSlice,
range: Range, range: Range,
textobject: TextObject, textobject: TextObject,
@ -378,8 +378,8 @@ mod test {
for (before, expected) in tests { for (before, expected) in tests {
let (s, selection) = crate::test::print(before); let (s, selection) = crate::test::print(before);
let text = Rope::from(s.as_str()); let text = Rope::from(s.as_str());
let selection = let selection = selection
selection.transform(|r| textobject_para(text.slice(..), r, TextObject::Inside, 1)); .transform(|r| textobject_paragraph(text.slice(..), r, TextObject::Inside, 1));
let actual = crate::test::plain(&s, selection); let actual = crate::test::plain(&s, selection);
assert_eq!(actual, expected, "\nbefore: `{before:?}`"); assert_eq!(actual, expected, "\nbefore: `{before:?}`");
} }
@ -401,8 +401,8 @@ mod test {
for (before, expected) in tests { for (before, expected) in tests {
let (s, selection) = crate::test::print(before); let (s, selection) = crate::test::print(before);
let text = Rope::from(s.as_str()); let text = Rope::from(s.as_str());
let selection = let selection = selection
selection.transform(|r| textobject_para(text.slice(..), r, TextObject::Inside, 2)); .transform(|r| textobject_paragraph(text.slice(..), r, TextObject::Inside, 2));
let actual = crate::test::plain(&s, selection); let actual = crate::test::plain(&s, selection);
assert_eq!(actual, expected, "\nbefore: `{before:?}`"); assert_eq!(actual, expected, "\nbefore: `{before:?}`");
} }
@ -432,8 +432,8 @@ mod test {
for (before, expected) in tests { for (before, expected) in tests {
let (s, selection) = crate::test::print(before); let (s, selection) = crate::test::print(before);
let text = Rope::from(s.as_str()); let text = Rope::from(s.as_str());
let selection = let selection = selection
selection.transform(|r| textobject_para(text.slice(..), r, TextObject::Around, 1)); .transform(|r| textobject_paragraph(text.slice(..), r, TextObject::Around, 1));
let actual = crate::test::plain(&s, selection); let actual = crate::test::plain(&s, selection);
assert_eq!(actual, expected, "\nbefore: `{before:?}`"); assert_eq!(actual, expected, "\nbefore: `{before:?}`");
} }

@ -209,8 +209,8 @@ impl MappableCommand {
move_next_long_word_start, "Move to beginning of next long word", move_next_long_word_start, "Move to beginning of next long word",
move_prev_long_word_start, "Move to beginning of previous long word", move_prev_long_word_start, "Move to beginning of previous long word",
move_next_long_word_end, "Move to end of next long word", move_next_long_word_end, "Move to end of next long word",
move_prev_para, "Move to previous paragraph", move_prev_paragraph, "Move to previous paragraph",
move_next_para, "Move to next paragraph", move_next_paragraph, "Move to next paragraph",
extend_next_word_start, "Extend to beginning of next word", extend_next_word_start, "Extend to beginning of next word",
extend_prev_word_start, "Extend to beginning of previous word", extend_prev_word_start, "Extend to beginning of previous word",
extend_next_long_word_start, "Extend to beginning of next long word", extend_next_long_word_start, "Extend to beginning of next long word",
@ -924,12 +924,12 @@ where
doc.set_selection(view.id, selection); doc.set_selection(view.id, selection);
} }
fn move_prev_para(cx: &mut Context) { fn move_prev_paragraph(cx: &mut Context) {
move_para_impl(cx, movement::move_prev_para) move_para_impl(cx, movement::move_prev_paragraph)
} }
fn move_next_para(cx: &mut Context) { fn move_next_paragraph(cx: &mut Context) {
move_para_impl(cx, movement::move_next_para) move_para_impl(cx, movement::move_next_paragraph)
} }
fn goto_file_start(cx: &mut Context) { fn goto_file_start(cx: &mut Context) {
@ -3991,7 +3991,7 @@ fn select_textobject(cx: &mut Context, objtype: textobject::TextObject) {
'f' => textobject_treesitter("function", range), 'f' => textobject_treesitter("function", range),
'a' => textobject_treesitter("parameter", range), 'a' => textobject_treesitter("parameter", range),
'o' => textobject_treesitter("comment", range), 'o' => textobject_treesitter("comment", range),
'p' => textobject::textobject_para(text, range, objtype, count), 'p' => textobject::textobject_paragraph(text, range, objtype, count),
'm' => { 'm' => {
let ch = text.char(range.cursor(text)); let ch = text.char(range.cursor(text));
if !ch.is_ascii_alphanumeric() { if !ch.is_ascii_alphanumeric() {

@ -104,7 +104,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
"c" => goto_prev_class, "c" => goto_prev_class,
"a" => goto_prev_parameter, "a" => goto_prev_parameter,
"o" => goto_prev_comment, "o" => goto_prev_comment,
"p" => move_prev_para, "p" => move_prev_paragraph,
"space" => add_newline_above, "space" => add_newline_above,
}, },
"]" => { "Right bracket" "]" => { "Right bracket"
@ -114,7 +114,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
"c" => goto_next_class, "c" => goto_next_class,
"a" => goto_next_parameter, "a" => goto_next_parameter,
"o" => goto_next_comment, "o" => goto_next_comment,
"p" => move_next_para, "p" => move_next_paragraph,
"space" => add_newline_below, "space" => add_newline_below,
}, },

Loading…
Cancel
Save