Add move_to method to Editor
This commit is contained in:
parent
63e9eeffb5
commit
4428f31b4f
4 changed files with 295 additions and 258 deletions
|
|
@ -190,6 +190,8 @@ impl text::Editor for () {
|
||||||
|
|
||||||
fn perform(&mut self, _action: text::editor::Action) {}
|
fn perform(&mut self, _action: text::editor::Action) {}
|
||||||
|
|
||||||
|
fn move_to(&mut self, _cursor: text::editor::Cursor) {}
|
||||||
|
|
||||||
fn bounds(&self) -> Size {
|
fn bounds(&self) -> Size {
|
||||||
Size::ZERO
|
Size::ZERO
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,9 @@ pub trait Editor: Sized + Default {
|
||||||
/// Performs an [`Action`] on the [`Editor`].
|
/// Performs an [`Action`] on the [`Editor`].
|
||||||
fn perform(&mut self, action: Action);
|
fn perform(&mut self, action: Action);
|
||||||
|
|
||||||
|
/// Moves the cursor to the given position.
|
||||||
|
fn move_to(&mut self, cursor: Cursor);
|
||||||
|
|
||||||
/// Returns the current boundaries of the [`Editor`].
|
/// Returns the current boundaries of the [`Editor`].
|
||||||
fn bounds(&self) -> Size;
|
fn bounds(&self) -> Size;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,31 @@ impl Editor {
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.expect("Editor should always be initialized")
|
.expect("Editor should always be initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn with_internal_mut<T>(
|
||||||
|
&mut self,
|
||||||
|
f: impl FnOnce(&mut Internal) -> T,
|
||||||
|
) -> T {
|
||||||
|
let editor =
|
||||||
|
self.0.take().expect("Editor should always be initialized");
|
||||||
|
|
||||||
|
// TODO: Handle multiple strong references somehow
|
||||||
|
let mut internal = Arc::try_unwrap(editor)
|
||||||
|
.expect("Editor cannot have multiple strong references");
|
||||||
|
|
||||||
|
// Clear cursor cache
|
||||||
|
let _ = internal
|
||||||
|
.selection
|
||||||
|
.write()
|
||||||
|
.expect("Write to cursor cache")
|
||||||
|
.take();
|
||||||
|
|
||||||
|
let result = f(&mut internal);
|
||||||
|
|
||||||
|
self.0 = Some(Arc::new(internal));
|
||||||
|
|
||||||
|
result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl editor::Editor for Editor {
|
impl editor::Editor for Editor {
|
||||||
|
|
@ -281,213 +306,228 @@ impl editor::Editor for Editor {
|
||||||
let mut font_system =
|
let mut font_system =
|
||||||
text::font_system().write().expect("Write font system");
|
text::font_system().write().expect("Write font system");
|
||||||
|
|
||||||
let editor =
|
self.with_internal_mut(|internal| {
|
||||||
self.0.take().expect("Editor should always be initialized");
|
let editor = &mut internal.editor;
|
||||||
|
|
||||||
// TODO: Handle multiple strong references somehow
|
match action {
|
||||||
let mut internal = Arc::try_unwrap(editor)
|
// Motion events
|
||||||
.expect("Editor cannot have multiple strong references");
|
Action::Move(motion) => {
|
||||||
|
if let Some((start, end)) = editor.selection_bounds() {
|
||||||
|
editor.set_selection(cosmic_text::Selection::None);
|
||||||
|
|
||||||
let editor = &mut internal.editor;
|
match motion {
|
||||||
|
// These motions are performed as-is even when a selection
|
||||||
// Clear cursor cache
|
// is present
|
||||||
let _ = internal
|
Motion::Home
|
||||||
.selection
|
| Motion::End
|
||||||
.write()
|
| Motion::DocumentStart
|
||||||
.expect("Write to cursor cache")
|
| Motion::DocumentEnd => {
|
||||||
.take();
|
editor.action(
|
||||||
|
font_system.raw(),
|
||||||
match action {
|
cosmic_text::Action::Motion(to_motion(
|
||||||
// Motion events
|
motion,
|
||||||
Action::Move(motion) => {
|
)),
|
||||||
if let Some((start, end)) = editor.selection_bounds() {
|
);
|
||||||
editor.set_selection(cosmic_text::Selection::None);
|
}
|
||||||
|
// Other motions simply move the cursor to one end of the selection
|
||||||
match motion {
|
_ => editor.set_cursor(match motion.direction() {
|
||||||
// These motions are performed as-is even when a selection
|
Direction::Left => start,
|
||||||
// is present
|
Direction::Right => end,
|
||||||
Motion::Home
|
}),
|
||||||
| Motion::End
|
|
||||||
| Motion::DocumentStart
|
|
||||||
| Motion::DocumentEnd => {
|
|
||||||
editor.action(
|
|
||||||
font_system.raw(),
|
|
||||||
cosmic_text::Action::Motion(to_motion(motion)),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
// Other motions simply move the cursor to one end of the selection
|
} else {
|
||||||
_ => editor.set_cursor(match motion.direction() {
|
editor.action(
|
||||||
Direction::Left => start,
|
font_system.raw(),
|
||||||
Direction::Right => end,
|
cosmic_text::Action::Motion(to_motion(motion)),
|
||||||
}),
|
);
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
// Selection events
|
||||||
|
Action::Select(motion) => {
|
||||||
|
let cursor = editor.cursor();
|
||||||
|
|
||||||
|
if editor.selection_bounds().is_none() {
|
||||||
|
editor.set_selection(cosmic_text::Selection::Normal(
|
||||||
|
cursor,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
editor.action(
|
editor.action(
|
||||||
font_system.raw(),
|
font_system.raw(),
|
||||||
cosmic_text::Action::Motion(to_motion(motion)),
|
cosmic_text::Action::Motion(to_motion(motion)),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Deselect if selection matches cursor position
|
||||||
|
if let Some((start, end)) = editor.selection_bounds()
|
||||||
|
&& start.line == end.line
|
||||||
|
&& start.index == end.index
|
||||||
|
{
|
||||||
|
editor.set_selection(cosmic_text::Selection::None);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
Action::SelectWord => {
|
||||||
|
|
||||||
// Selection events
|
|
||||||
Action::Select(motion) => {
|
|
||||||
let cursor = editor.cursor();
|
|
||||||
|
|
||||||
if editor.selection_bounds().is_none() {
|
|
||||||
editor
|
|
||||||
.set_selection(cosmic_text::Selection::Normal(cursor));
|
|
||||||
}
|
|
||||||
|
|
||||||
editor.action(
|
|
||||||
font_system.raw(),
|
|
||||||
cosmic_text::Action::Motion(to_motion(motion)),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Deselect if selection matches cursor position
|
|
||||||
if let Some((start, end)) = editor.selection_bounds()
|
|
||||||
&& start.line == end.line
|
|
||||||
&& start.index == end.index
|
|
||||||
{
|
|
||||||
editor.set_selection(cosmic_text::Selection::None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Action::SelectWord => {
|
|
||||||
let cursor = editor.cursor();
|
|
||||||
|
|
||||||
editor.set_selection(cosmic_text::Selection::Word(cursor));
|
|
||||||
}
|
|
||||||
Action::SelectLine => {
|
|
||||||
let cursor = editor.cursor();
|
|
||||||
|
|
||||||
editor.set_selection(cosmic_text::Selection::Line(cursor));
|
|
||||||
}
|
|
||||||
Action::SelectAll => {
|
|
||||||
let buffer = buffer_from_editor(editor);
|
|
||||||
|
|
||||||
if buffer.lines.len() > 1
|
|
||||||
|| buffer
|
|
||||||
.lines
|
|
||||||
.first()
|
|
||||||
.is_some_and(|line| !line.text().is_empty())
|
|
||||||
{
|
|
||||||
let cursor = editor.cursor();
|
let cursor = editor.cursor();
|
||||||
|
|
||||||
editor.set_selection(cosmic_text::Selection::Normal(
|
editor.set_selection(cosmic_text::Selection::Word(cursor));
|
||||||
cosmic_text::Cursor {
|
}
|
||||||
line: 0,
|
Action::SelectLine => {
|
||||||
index: 0,
|
let cursor = editor.cursor();
|
||||||
..cursor
|
|
||||||
},
|
|
||||||
));
|
|
||||||
|
|
||||||
|
editor.set_selection(cosmic_text::Selection::Line(cursor));
|
||||||
|
}
|
||||||
|
Action::SelectAll => {
|
||||||
|
let buffer = buffer_from_editor(editor);
|
||||||
|
|
||||||
|
if buffer.lines.len() > 1
|
||||||
|
|| buffer
|
||||||
|
.lines
|
||||||
|
.first()
|
||||||
|
.is_some_and(|line| !line.text().is_empty())
|
||||||
|
{
|
||||||
|
let cursor = editor.cursor();
|
||||||
|
|
||||||
|
editor.set_selection(cosmic_text::Selection::Normal(
|
||||||
|
cosmic_text::Cursor {
|
||||||
|
line: 0,
|
||||||
|
index: 0,
|
||||||
|
..cursor
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
|
editor.action(
|
||||||
|
font_system.raw(),
|
||||||
|
cosmic_text::Action::Motion(
|
||||||
|
cosmic_text::Motion::BufferEnd,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Editing events
|
||||||
|
Action::Edit(edit) => {
|
||||||
|
let topmost_line_before_edit = editor
|
||||||
|
.selection_bounds()
|
||||||
|
.map(|(start, _)| start)
|
||||||
|
.unwrap_or_else(|| editor.cursor())
|
||||||
|
.line;
|
||||||
|
|
||||||
|
match edit {
|
||||||
|
Edit::Insert(c) => {
|
||||||
|
editor.action(
|
||||||
|
font_system.raw(),
|
||||||
|
cosmic_text::Action::Insert(c),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Edit::Paste(text) => {
|
||||||
|
editor.insert_string(&text, None);
|
||||||
|
}
|
||||||
|
Edit::Indent => {
|
||||||
|
editor.action(
|
||||||
|
font_system.raw(),
|
||||||
|
cosmic_text::Action::Indent,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Edit::Unindent => {
|
||||||
|
editor.action(
|
||||||
|
font_system.raw(),
|
||||||
|
cosmic_text::Action::Unindent,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Edit::Enter => {
|
||||||
|
editor.action(
|
||||||
|
font_system.raw(),
|
||||||
|
cosmic_text::Action::Enter,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Edit::Backspace => {
|
||||||
|
editor.action(
|
||||||
|
font_system.raw(),
|
||||||
|
cosmic_text::Action::Backspace,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Edit::Delete => {
|
||||||
|
editor.action(
|
||||||
|
font_system.raw(),
|
||||||
|
cosmic_text::Action::Delete,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let cursor = editor.cursor();
|
||||||
|
let selection_start = editor
|
||||||
|
.selection_bounds()
|
||||||
|
.map(|(start, _)| start)
|
||||||
|
.unwrap_or(cursor);
|
||||||
|
|
||||||
|
internal.topmost_line_changed = Some(
|
||||||
|
selection_start.line.min(topmost_line_before_edit),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mouse events
|
||||||
|
Action::Click(position) => {
|
||||||
editor.action(
|
editor.action(
|
||||||
font_system.raw(),
|
font_system.raw(),
|
||||||
cosmic_text::Action::Motion(
|
cosmic_text::Action::Click {
|
||||||
cosmic_text::Motion::BufferEnd,
|
x: position.x as i32,
|
||||||
),
|
y: position.y as i32,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Action::Drag(position) => {
|
||||||
|
editor.action(
|
||||||
|
font_system.raw(),
|
||||||
|
cosmic_text::Action::Drag {
|
||||||
|
x: position.x as i32,
|
||||||
|
y: position.y as i32,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// Deselect if selection matches cursor position
|
||||||
|
if let Some((start, end)) = editor.selection_bounds()
|
||||||
|
&& start.line == end.line
|
||||||
|
&& start.index == end.index
|
||||||
|
{
|
||||||
|
editor.set_selection(cosmic_text::Selection::None);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Action::Scroll { lines } => {
|
||||||
|
editor.action(
|
||||||
|
font_system.raw(),
|
||||||
|
cosmic_text::Action::Scroll {
|
||||||
|
pixels: lines as f32
|
||||||
|
* buffer_from_editor(editor)
|
||||||
|
.metrics()
|
||||||
|
.line_height,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Editing events
|
fn move_to(&mut self, cursor: Cursor) {
|
||||||
Action::Edit(edit) => {
|
self.with_internal_mut(|internal| {
|
||||||
let topmost_line_before_edit = editor
|
// TODO: Expose `Affinity`
|
||||||
.selection_bounds()
|
internal.editor.set_cursor(cosmic_text::Cursor {
|
||||||
.map(|(start, _)| start)
|
line: cursor.position.line,
|
||||||
.unwrap_or_else(|| editor.cursor())
|
index: cursor.position.column,
|
||||||
.line;
|
affinity: cosmic_text::Affinity::Before,
|
||||||
|
});
|
||||||
|
|
||||||
match edit {
|
if let Some(selection) = cursor.selection {
|
||||||
Edit::Insert(c) => {
|
internal
|
||||||
editor.action(
|
.editor
|
||||||
font_system.raw(),
|
.set_selection(cosmic_text::Selection::Normal(
|
||||||
cosmic_text::Action::Insert(c),
|
cosmic_text::Cursor {
|
||||||
);
|
line: selection.line,
|
||||||
}
|
index: selection.column,
|
||||||
Edit::Paste(text) => {
|
affinity: cosmic_text::Affinity::Before,
|
||||||
editor.insert_string(&text, None);
|
},
|
||||||
}
|
));
|
||||||
Edit::Indent => {
|
|
||||||
editor.action(
|
|
||||||
font_system.raw(),
|
|
||||||
cosmic_text::Action::Indent,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Edit::Unindent => {
|
|
||||||
editor.action(
|
|
||||||
font_system.raw(),
|
|
||||||
cosmic_text::Action::Unindent,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Edit::Enter => {
|
|
||||||
editor.action(
|
|
||||||
font_system.raw(),
|
|
||||||
cosmic_text::Action::Enter,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Edit::Backspace => {
|
|
||||||
editor.action(
|
|
||||||
font_system.raw(),
|
|
||||||
cosmic_text::Action::Backspace,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Edit::Delete => {
|
|
||||||
editor.action(
|
|
||||||
font_system.raw(),
|
|
||||||
cosmic_text::Action::Delete,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let cursor = editor.cursor();
|
|
||||||
let selection_start = editor
|
|
||||||
.selection_bounds()
|
|
||||||
.map(|(start, _)| start)
|
|
||||||
.unwrap_or(cursor);
|
|
||||||
|
|
||||||
internal.topmost_line_changed =
|
|
||||||
Some(selection_start.line.min(topmost_line_before_edit));
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
// Mouse events
|
|
||||||
Action::Click(position) => {
|
|
||||||
editor.action(
|
|
||||||
font_system.raw(),
|
|
||||||
cosmic_text::Action::Click {
|
|
||||||
x: position.x as i32,
|
|
||||||
y: position.y as i32,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Action::Drag(position) => {
|
|
||||||
editor.action(
|
|
||||||
font_system.raw(),
|
|
||||||
cosmic_text::Action::Drag {
|
|
||||||
x: position.x as i32,
|
|
||||||
y: position.y as i32,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// Deselect if selection matches cursor position
|
|
||||||
if let Some((start, end)) = editor.selection_bounds()
|
|
||||||
&& start.line == end.line
|
|
||||||
&& start.index == end.index
|
|
||||||
{
|
|
||||||
editor.set_selection(cosmic_text::Selection::None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Action::Scroll { lines } => {
|
|
||||||
editor.action(
|
|
||||||
font_system.raw(),
|
|
||||||
cosmic_text::Action::Scroll {
|
|
||||||
pixels: lines as f32
|
|
||||||
* buffer_from_editor(editor).metrics().line_height,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.0 = Some(Arc::new(internal));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bounds(&self) -> Size {
|
fn bounds(&self) -> Size {
|
||||||
|
|
@ -512,94 +552,83 @@ impl editor::Editor for Editor {
|
||||||
new_wrapping: Wrapping,
|
new_wrapping: Wrapping,
|
||||||
new_highlighter: &mut impl Highlighter,
|
new_highlighter: &mut impl Highlighter,
|
||||||
) {
|
) {
|
||||||
let editor =
|
self.with_internal_mut(|internal| {
|
||||||
self.0.take().expect("Editor should always be initialized");
|
let mut font_system =
|
||||||
|
text::font_system().write().expect("Write font system");
|
||||||
|
|
||||||
let mut internal = Arc::try_unwrap(editor)
|
let buffer = buffer_mut_from_editor(&mut internal.editor);
|
||||||
.expect("Editor cannot have multiple strong references");
|
|
||||||
|
|
||||||
let mut font_system =
|
if font_system.version() != internal.version {
|
||||||
text::font_system().write().expect("Write font system");
|
log::trace!("Updating `FontSystem` of `Editor`...");
|
||||||
|
|
||||||
let buffer = buffer_mut_from_editor(&mut internal.editor);
|
for line in buffer.lines.iter_mut() {
|
||||||
|
line.reset();
|
||||||
|
}
|
||||||
|
|
||||||
if font_system.version() != internal.version {
|
internal.version = font_system.version();
|
||||||
log::trace!("Updating `FontSystem` of `Editor`...");
|
internal.topmost_line_changed = Some(0);
|
||||||
|
|
||||||
for line in buffer.lines.iter_mut() {
|
|
||||||
line.reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal.version = font_system.version();
|
if new_font != internal.font {
|
||||||
internal.topmost_line_changed = Some(0);
|
log::trace!("Updating font of `Editor`...");
|
||||||
}
|
|
||||||
|
|
||||||
if new_font != internal.font {
|
for line in buffer.lines.iter_mut() {
|
||||||
log::trace!("Updating font of `Editor`...");
|
let _ = line.set_attrs_list(cosmic_text::AttrsList::new(
|
||||||
|
&text::to_attributes(new_font),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
for line in buffer.lines.iter_mut() {
|
internal.font = new_font;
|
||||||
let _ = line.set_attrs_list(cosmic_text::AttrsList::new(
|
internal.topmost_line_changed = Some(0);
|
||||||
&text::to_attributes(new_font),
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal.font = new_font;
|
let metrics = buffer.metrics();
|
||||||
internal.topmost_line_changed = Some(0);
|
let new_line_height = new_line_height.to_absolute(new_size);
|
||||||
}
|
|
||||||
|
|
||||||
let metrics = buffer.metrics();
|
if new_size.0 != metrics.font_size
|
||||||
let new_line_height = new_line_height.to_absolute(new_size);
|
|| new_line_height.0 != metrics.line_height
|
||||||
|
{
|
||||||
|
log::trace!("Updating `Metrics` of `Editor`...");
|
||||||
|
|
||||||
if new_size.0 != metrics.font_size
|
buffer.set_metrics(
|
||||||
|| new_line_height.0 != metrics.line_height
|
font_system.raw(),
|
||||||
{
|
cosmic_text::Metrics::new(new_size.0, new_line_height.0),
|
||||||
log::trace!("Updating `Metrics` of `Editor`...");
|
);
|
||||||
|
}
|
||||||
|
|
||||||
buffer.set_metrics(
|
let new_wrap = text::to_wrap(new_wrapping);
|
||||||
font_system.raw(),
|
|
||||||
cosmic_text::Metrics::new(new_size.0, new_line_height.0),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let new_wrap = text::to_wrap(new_wrapping);
|
if new_wrap != buffer.wrap() {
|
||||||
|
log::trace!("Updating `Wrap` strategy of `Editor`...");
|
||||||
|
|
||||||
if new_wrap != buffer.wrap() {
|
buffer.set_wrap(font_system.raw(), new_wrap);
|
||||||
log::trace!("Updating `Wrap` strategy of `Editor`...");
|
}
|
||||||
|
|
||||||
buffer.set_wrap(font_system.raw(), new_wrap);
|
if new_bounds != internal.bounds {
|
||||||
}
|
log::trace!("Updating size of `Editor`...");
|
||||||
|
|
||||||
if new_bounds != internal.bounds {
|
buffer.set_size(
|
||||||
log::trace!("Updating size of `Editor`...");
|
font_system.raw(),
|
||||||
|
Some(new_bounds.width),
|
||||||
|
Some(new_bounds.height),
|
||||||
|
);
|
||||||
|
|
||||||
buffer.set_size(
|
internal.bounds = new_bounds;
|
||||||
font_system.raw(),
|
}
|
||||||
Some(new_bounds.width),
|
|
||||||
Some(new_bounds.height),
|
|
||||||
);
|
|
||||||
|
|
||||||
internal.bounds = new_bounds;
|
if let Some(topmost_line_changed) =
|
||||||
}
|
internal.topmost_line_changed.take()
|
||||||
|
{
|
||||||
|
log::trace!(
|
||||||
|
"Notifying highlighter of line \
|
||||||
|
change: {topmost_line_changed}"
|
||||||
|
);
|
||||||
|
|
||||||
if let Some(topmost_line_changed) = internal.topmost_line_changed.take()
|
new_highlighter.change_line(topmost_line_changed);
|
||||||
{
|
}
|
||||||
log::trace!(
|
|
||||||
"Notifying highlighter of line change: {topmost_line_changed}"
|
|
||||||
);
|
|
||||||
|
|
||||||
new_highlighter.change_line(topmost_line_changed);
|
internal.editor.shape_as_needed(font_system.raw(), false);
|
||||||
}
|
});
|
||||||
|
|
||||||
internal.editor.shape_as_needed(font_system.raw(), false);
|
|
||||||
|
|
||||||
// Clear cursor cache
|
|
||||||
let _ = internal
|
|
||||||
.selection
|
|
||||||
.write()
|
|
||||||
.expect("Write to cursor cache")
|
|
||||||
.take();
|
|
||||||
|
|
||||||
self.0 = Some(Arc::new(internal));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn highlight<H: Highlighter>(
|
fn highlight<H: Highlighter>(
|
||||||
|
|
|
||||||
|
|
@ -390,7 +390,6 @@ where
|
||||||
R: text::Renderer,
|
R: text::Renderer,
|
||||||
{
|
{
|
||||||
editor: R::Editor,
|
editor: R::Editor,
|
||||||
is_dirty: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R> Content<R>
|
impl<R> Content<R>
|
||||||
|
|
@ -406,7 +405,6 @@ where
|
||||||
pub fn with_text(text: &str) -> Self {
|
pub fn with_text(text: &str) -> Self {
|
||||||
Self(RefCell::new(Internal {
|
Self(RefCell::new(Internal {
|
||||||
editor: R::Editor::with_text(text),
|
editor: R::Editor::with_text(text),
|
||||||
is_dirty: true,
|
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -415,7 +413,13 @@ where
|
||||||
let internal = self.0.get_mut();
|
let internal = self.0.get_mut();
|
||||||
|
|
||||||
internal.editor.perform(action);
|
internal.editor.perform(action);
|
||||||
internal.is_dirty = true;
|
}
|
||||||
|
|
||||||
|
/// Moves the current cursor to reflect the given one.
|
||||||
|
pub fn move_to(&mut self, cursor: Cursor) {
|
||||||
|
let internal = self.0.get_mut();
|
||||||
|
|
||||||
|
internal.editor.move_to(cursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the current cursor position of the [`Content`].
|
/// Returns the current cursor position of the [`Content`].
|
||||||
|
|
@ -511,7 +515,6 @@ where
|
||||||
|
|
||||||
f.debug_struct("Content")
|
f.debug_struct("Content")
|
||||||
.field("editor", &internal.editor)
|
.field("editor", &internal.editor)
|
||||||
.field("is_dirty", &internal.is_dirty)
|
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue