Use fork of cosmic-text with some minor fixes
This commit is contained in:
parent
d051f21597
commit
c9dbccba46
2 changed files with 5 additions and 35 deletions
|
|
@ -151,3 +151,7 @@ wgpu = "0.17"
|
||||||
winapi = "0.3"
|
winapi = "0.3"
|
||||||
window_clipboard = "0.3"
|
window_clipboard = "0.3"
|
||||||
winit = { git = "https://github.com/iced-rs/winit.git", rev = "c52db2045d0a2f1b8d9923870de1d4ab1994146e", default-features = false }
|
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"
|
||||||
|
|
|
||||||
|
|
@ -81,33 +81,7 @@ impl editor::Editor for Editor {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn selection(&self) -> Option<String> {
|
fn selection(&self) -> Option<String> {
|
||||||
let internal = self.internal();
|
self.internal().editor.copy_selection()
|
||||||
|
|
||||||
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"),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cursor(&self) -> editor::Cursor {
|
fn cursor(&self) -> editor::Cursor {
|
||||||
|
|
@ -400,14 +374,6 @@ impl editor::Editor for Editor {
|
||||||
}
|
}
|
||||||
Action::Paste(text) => {
|
Action::Paste(text) => {
|
||||||
editor.insert_string(&text, None);
|
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 => {
|
Action::Enter => {
|
||||||
editor.action(font_system.raw(), cosmic_text::Action::Enter);
|
editor.action(font_system.raw(), cosmic_text::Action::Enter);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue