Use fork of cosmic-text with some minor fixes

This commit is contained in:
Héctor Ramón Jiménez 2023-09-16 16:27:02 +02:00
parent d051f21597
commit c9dbccba46
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
2 changed files with 5 additions and 35 deletions

View file

@ -151,3 +151,7 @@ wgpu = "0.17"
winapi = "0.3"
window_clipboard = "0.3"
winit = { git = "https://github.com/iced-rs/winit.git", rev = "c52db2045d0a2f1b8d9923870de1d4ab1994146e", default-features = false }
[patch.crates-io.cosmic-text]
git = "https://github.com/hecrj/cosmic-text.git"
rev = "cb83458e7d0b84ef37c5beb72dda5046d7d343a6"

View file

@ -81,33 +81,7 @@ impl editor::Editor for Editor {
}
fn selection(&self) -> Option<String> {
let internal = self.internal();
let cursor = internal.editor.cursor();
let selection = internal.editor.select_opt()?;
let (start, end) = if cursor < selection {
(cursor, selection)
} else {
(selection, cursor)
};
Some(
internal.editor.buffer().lines[start.line..=end.line]
.iter()
.enumerate()
.map(|(i, line)| {
if i == 0 {
&line.text()[start.index..]
} else if i == end.line - start.line {
&line.text()[..end.index]
} else {
line.text()
}
})
.collect::<Vec<_>>()
.join("\n"),
)
self.internal().editor.copy_selection()
}
fn cursor(&self) -> editor::Cursor {
@ -400,14 +374,6 @@ impl editor::Editor for Editor {
}
Action::Paste(text) => {
editor.insert_string(&text, None);
// TODO: Fix cosmic-text
// Cursor should be marked as moved after `insert_string`.
let cursor = editor.cursor();
editor
.buffer_mut()
.shape_until_cursor(font_system.raw(), cursor);
}
Action::Enter => {
editor.action(font_system.raw(), cosmic_text::Action::Enter);