MCPcopy Create free account
hub / github.com/Kethku/Pando / insert_or_replace_selection

Method insert_or_replace_selection

aspen/src/components/editor.rs:89–106  ·  view source on GitHub ↗

Insert at cursor, or replace selection.

(&mut self, s: &str, cx: &Context)

Source from the content-addressed store, hash-verified

87
88 /// Insert at cursor, or replace selection.
89 pub fn insert_or_replace_selection(&mut self, s: &str, cx: &Context) {
90 let range = self.selection.text_range();
91 let start = range.start;
92 if self.selection.is_collapsed() {
93 self.buffer.insert_str(start, s);
94 } else {
95 self.buffer.replace_range(range.clone(), s);
96 }
97 self.update_layout(cx);
98
99 let new_index = start.saturating_add(s.len());
100 let affinity = if s.ends_with("\n") {
101 Affinity::Downstream
102 } else {
103 Affinity::Upstream
104 };
105 self.set_selection(Cursor::from_byte_index(&self.layout, new_index, affinity).into());
106 }
107
108 /// Delete the selection.
109 pub fn delete_selection(&mut self, cx: &Context) {

Callers 2

delete_selectionMethod · 0.80
handle_pressed_keyMethod · 0.80

Calls 2

update_layoutMethod · 0.80
set_selectionMethod · 0.80

Tested by

no test coverage detected