Make Editor::buffer_ref accessible, rename lifetimes
This commit is contained in:
parent
cbbf6f0d8f
commit
0a11fb1045
5 changed files with 108 additions and 91 deletions
|
|
@ -372,7 +372,7 @@ impl Application for Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_attrs<T: Edit>(editor: &mut T, attrs: Attrs) {
|
fn update_attrs<'buffer, E: Edit<'buffer>>(editor: &mut E, attrs: Attrs) {
|
||||||
editor.with_buffer_mut(|buffer| {
|
editor.with_buffer_mut(|buffer| {
|
||||||
buffer.lines.iter_mut().for_each(|line| {
|
buffer.lines.iter_mut().for_each(|line| {
|
||||||
line.set_attrs_list(AttrsList::new(attrs));
|
line.set_attrs_list(AttrsList::new(attrs));
|
||||||
|
|
@ -380,7 +380,7 @@ fn update_attrs<T: Edit>(editor: &mut T, attrs: Attrs) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_alignment<T: Edit>(editor: &mut T, align: Align) {
|
fn update_alignment<'buffer, E: Edit<'buffer>>(editor: &mut E, align: Align) {
|
||||||
let current_line = editor.cursor().line;
|
let current_line = editor.cursor().line;
|
||||||
let selection_bounds_opt = editor.selection_bounds();
|
let selection_bounds_opt = editor.selection_bounds();
|
||||||
editor.with_buffer_mut(|buffer| {
|
editor.with_buffer_mut(|buffer| {
|
||||||
|
|
|
||||||
|
|
@ -2,46 +2,20 @@
|
||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
use alloc::string::{String, ToString};
|
use alloc::string::{String, ToString};
|
||||||
use alloc::sync::Arc;
|
|
||||||
use core::{cmp, iter::once};
|
use core::{cmp, iter::once};
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
|
||||||
#[cfg(feature = "swash")]
|
#[cfg(feature = "swash")]
|
||||||
use crate::Color;
|
use crate::Color;
|
||||||
use crate::{
|
use crate::{
|
||||||
Action, AttrsList, BorrowedWithFontSystem, Buffer, BufferLine, Change, ChangeItem, Cursor,
|
Action, AttrsList, BorrowedWithFontSystem, BufferLine, BufferRef, Change, ChangeItem, Cursor,
|
||||||
Edit, FontSystem, Selection, Shaping,
|
Edit, FontSystem, Selection, Shaping,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum BufferRef<'a> {
|
|
||||||
Owned(Buffer),
|
|
||||||
Borrowed(&'a mut Buffer),
|
|
||||||
Arc(Arc<Buffer>),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<Buffer> for BufferRef<'a> {
|
|
||||||
fn from(buffer: Buffer) -> Self {
|
|
||||||
Self::Owned(buffer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<&'a mut Buffer> for BufferRef<'a> {
|
|
||||||
fn from(buffer: &'a mut Buffer) -> Self {
|
|
||||||
Self::Borrowed(buffer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> From<Arc<Buffer>> for BufferRef<'a> {
|
|
||||||
fn from(arc: Arc<Buffer>) -> Self {
|
|
||||||
Self::Arc(arc)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A wrapper of [`Buffer`] for easy editing
|
/// A wrapper of [`Buffer`] for easy editing
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Editor<'a> {
|
pub struct Editor<'buffer> {
|
||||||
buffer_ref: BufferRef<'a>,
|
buffer_ref: BufferRef<'buffer>,
|
||||||
cursor: Cursor,
|
cursor: Cursor,
|
||||||
cursor_x_opt: Option<i32>,
|
cursor_x_opt: Option<i32>,
|
||||||
selection: Selection,
|
selection: Selection,
|
||||||
|
|
@ -51,9 +25,9 @@ pub struct Editor<'a> {
|
||||||
change: Option<Change>,
|
change: Option<Change>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Editor<'a> {
|
impl<'buffer> Editor<'buffer> {
|
||||||
/// Create a new [`Editor`] with the provided [`Buffer`]
|
/// Create a new [`Editor`] with the provided [`Buffer`]
|
||||||
pub fn new(buffer: impl Into<BufferRef<'a>>) -> Self {
|
pub fn new(buffer: impl Into<BufferRef<'buffer>>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
buffer_ref: buffer.into(),
|
buffer_ref: buffer.into(),
|
||||||
cursor: Cursor::default(),
|
cursor: Cursor::default(),
|
||||||
|
|
@ -241,25 +215,13 @@ impl<'a> Editor<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Edit for Editor<'a> {
|
impl<'buffer> Edit<'buffer> for Editor<'buffer> {
|
||||||
fn with_buffer<F: FnOnce(&Buffer) -> T, T>(&self, f: F) -> T {
|
fn buffer_ref(&self) -> &BufferRef<'buffer> {
|
||||||
match &self.buffer_ref {
|
&self.buffer_ref
|
||||||
BufferRef::Owned(buffer) => f(buffer),
|
|
||||||
BufferRef::Borrowed(buffer) => f(buffer),
|
|
||||||
BufferRef::Arc(buffer) => f(buffer),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_buffer_mut<F: FnOnce(&mut Buffer) -> T, T>(&mut self, f: F) -> T {
|
fn buffer_ref_mut(&mut self) -> &mut BufferRef<'buffer> {
|
||||||
match &mut self.buffer_ref {
|
&mut self.buffer_ref
|
||||||
BufferRef::Owned(buffer) => f(buffer),
|
|
||||||
BufferRef::Borrowed(buffer) => f(buffer),
|
|
||||||
BufferRef::Arc(arc) => match Arc::get_mut(arc) {
|
|
||||||
Some(buffer) => f(buffer),
|
|
||||||
//TODO: use make_mut?
|
|
||||||
None => panic!("BufferRef::Arc cannot be accessed mutibly"),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cursor(&self) -> Cursor {
|
fn cursor(&self) -> Cursor {
|
||||||
|
|
@ -886,7 +848,7 @@ impl<'a> Edit for Editor<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> BorrowedWithFontSystem<'a, Editor<'b>> {
|
impl<'font_system, 'buffer> BorrowedWithFontSystem<'font_system, Editor<'buffer>> {
|
||||||
#[cfg(feature = "swash")]
|
#[cfg(feature = "swash")]
|
||||||
pub fn draw<F>(
|
pub fn draw<F>(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
use alloc::sync::Arc;
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
use alloc::{string::String, vec::Vec};
|
use alloc::{string::String, vec::Vec};
|
||||||
use core::cmp;
|
use core::cmp;
|
||||||
|
|
@ -63,6 +64,31 @@ pub enum Action {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum BufferRef<'buffer> {
|
||||||
|
Owned(Buffer),
|
||||||
|
Borrowed(&'buffer mut Buffer),
|
||||||
|
Arc(Arc<Buffer>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'buffer> From<Buffer> for BufferRef<'buffer> {
|
||||||
|
fn from(buffer: Buffer) -> Self {
|
||||||
|
Self::Owned(buffer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'buffer> From<&'buffer mut Buffer> for BufferRef<'buffer> {
|
||||||
|
fn from(buffer: &'buffer mut Buffer) -> Self {
|
||||||
|
Self::Borrowed(buffer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'buffer> From<Arc<Buffer>> for BufferRef<'buffer> {
|
||||||
|
fn from(arc: Arc<Buffer>) -> Self {
|
||||||
|
Self::Arc(arc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A unique change to an editor
|
/// A unique change to an editor
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct ChangeItem {
|
pub struct ChangeItem {
|
||||||
|
|
@ -115,12 +141,12 @@ pub enum Selection {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A trait to allow easy replacements of [`Editor`], like `SyntaxEditor`
|
/// A trait to allow easy replacements of [`Editor`], like `SyntaxEditor`
|
||||||
pub trait Edit {
|
pub trait Edit<'buffer> {
|
||||||
/// Mutably borrows `self` together with an [`FontSystem`] for more convenient methods
|
/// Mutably borrows `self` together with an [`FontSystem`] for more convenient methods
|
||||||
fn borrow_with<'a>(
|
fn borrow_with<'font_system>(
|
||||||
&'a mut self,
|
&'font_system mut self,
|
||||||
font_system: &'a mut FontSystem,
|
font_system: &'font_system mut FontSystem,
|
||||||
) -> BorrowedWithFontSystem<'a, Self>
|
) -> BorrowedWithFontSystem<'font_system, Self>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
|
|
@ -130,11 +156,33 @@ pub trait Edit {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the internal [`BufferRef`]
|
||||||
|
fn buffer_ref(&self) -> &BufferRef<'buffer>;
|
||||||
|
|
||||||
|
/// Get the internal [`BufferRef`]
|
||||||
|
fn buffer_ref_mut(&mut self) -> &mut BufferRef<'buffer>;
|
||||||
|
|
||||||
/// Get the internal [`Buffer`]
|
/// Get the internal [`Buffer`]
|
||||||
fn with_buffer<F: FnOnce(&Buffer) -> T, T>(&self, f: F) -> T;
|
fn with_buffer<F: FnOnce(&Buffer) -> T, T>(&self, f: F) -> T {
|
||||||
|
match self.buffer_ref() {
|
||||||
|
BufferRef::Owned(buffer) => f(buffer),
|
||||||
|
BufferRef::Borrowed(buffer) => f(buffer),
|
||||||
|
BufferRef::Arc(buffer) => f(buffer),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the internal [`Buffer`], mutably
|
/// Get the internal [`Buffer`], mutably
|
||||||
fn with_buffer_mut<F: FnOnce(&mut Buffer) -> T, T>(&mut self, f: F) -> T;
|
fn with_buffer_mut<F: FnOnce(&mut Buffer) -> T, T>(&mut self, f: F) -> T {
|
||||||
|
match self.buffer_ref_mut() {
|
||||||
|
BufferRef::Owned(buffer) => f(buffer),
|
||||||
|
BufferRef::Borrowed(buffer) => f(buffer),
|
||||||
|
BufferRef::Arc(arc) => match Arc::get_mut(arc) {
|
||||||
|
Some(buffer) => f(buffer),
|
||||||
|
//TODO: use make_mut?
|
||||||
|
None => panic!("BufferRef::Arc cannot be accessed mutibly"),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Get the [`Buffer`] redraw flag
|
/// Get the [`Buffer`] redraw flag
|
||||||
fn redraw(&self) -> bool {
|
fn redraw(&self) -> bool {
|
||||||
|
|
@ -277,7 +325,7 @@ pub trait Edit {
|
||||||
fn action(&mut self, font_system: &mut FontSystem, action: Action);
|
fn action(&mut self, font_system: &mut FontSystem, action: Action);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, E: Edit> BorrowedWithFontSystem<'a, E> {
|
impl<'font_system, 'buffer, E: Edit<'buffer>> BorrowedWithFontSystem<'font_system, E> {
|
||||||
/// Get the internal [`Buffer`], mutably
|
/// Get the internal [`Buffer`], mutably
|
||||||
pub fn with_buffer_mut<F: FnOnce(&mut BorrowedWithFontSystem<Buffer>) -> T, T>(
|
pub fn with_buffer_mut<F: FnOnce(&mut BorrowedWithFontSystem<Buffer>) -> T, T>(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ use syntect::highlighting::{
|
||||||
use syntect::parsing::{ParseState, ScopeStack, SyntaxReference, SyntaxSet};
|
use syntect::parsing::{ParseState, ScopeStack, SyntaxReference, SyntaxSet};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Action, AttrsList, BorrowedWithFontSystem, Buffer, BufferRef, Change, Color, Cursor, Edit,
|
Action, AttrsList, BorrowedWithFontSystem, BufferRef, Change, Color, Cursor, Edit, Editor,
|
||||||
Editor, FontSystem, Selection, Shaping, Style, Weight,
|
FontSystem, Selection, Shaping, Style, Weight,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use syntect::highlighting::Theme as SyntaxTheme;
|
pub use syntect::highlighting::Theme as SyntaxTheme;
|
||||||
|
|
@ -33,24 +33,24 @@ impl SyntaxSystem {
|
||||||
|
|
||||||
/// A wrapper of [`Editor`] with syntax highlighting provided by [`SyntaxSystem`]
|
/// A wrapper of [`Editor`] with syntax highlighting provided by [`SyntaxSystem`]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct SyntaxEditor<'a, 'b> {
|
pub struct SyntaxEditor<'syntax_system, 'buffer> {
|
||||||
editor: Editor<'b>,
|
editor: Editor<'buffer>,
|
||||||
syntax_system: &'a SyntaxSystem,
|
syntax_system: &'syntax_system SyntaxSystem,
|
||||||
syntax: &'a SyntaxReference,
|
syntax: &'syntax_system SyntaxReference,
|
||||||
theme: &'a SyntaxTheme,
|
theme: &'syntax_system SyntaxTheme,
|
||||||
highlighter: Highlighter<'a>,
|
highlighter: Highlighter<'syntax_system>,
|
||||||
syntax_cache: Vec<(ParseState, ScopeStack)>,
|
syntax_cache: Vec<(ParseState, ScopeStack)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> SyntaxEditor<'a, 'b> {
|
impl<'syntax_system, 'buffer> SyntaxEditor<'syntax_system, 'buffer> {
|
||||||
/// Create a new [`SyntaxEditor`] with the provided [`Buffer`], [`SyntaxSystem`], and theme name.
|
/// Create a new [`SyntaxEditor`] with the provided [`Buffer`], [`SyntaxSystem`], and theme name.
|
||||||
///
|
///
|
||||||
/// A good default theme name is "base16-eighties.dark".
|
/// A good default theme name is "base16-eighties.dark".
|
||||||
///
|
///
|
||||||
/// Returns None if theme not found
|
/// Returns None if theme not found
|
||||||
pub fn new(
|
pub fn new(
|
||||||
buffer: impl Into<BufferRef<'b>>,
|
buffer: impl Into<BufferRef<'buffer>>,
|
||||||
syntax_system: &'a SyntaxSystem,
|
syntax_system: &'syntax_system SyntaxSystem,
|
||||||
theme_name: &str,
|
theme_name: &str,
|
||||||
) -> Option<Self> {
|
) -> Option<Self> {
|
||||||
let editor = Editor::new(buffer);
|
let editor = Editor::new(buffer);
|
||||||
|
|
@ -213,13 +213,13 @@ impl<'a, 'b> SyntaxEditor<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> Edit for SyntaxEditor<'a, 'b> {
|
impl<'syntax_system, 'buffer> Edit<'buffer> for SyntaxEditor<'syntax_system, 'buffer> {
|
||||||
fn with_buffer<F: FnOnce(&Buffer) -> T, T>(&self, f: F) -> T {
|
fn buffer_ref(&self) -> &BufferRef<'buffer> {
|
||||||
self.editor.with_buffer(f)
|
self.editor.buffer_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_buffer_mut<F: FnOnce(&mut Buffer) -> T, T>(&mut self, f: F) -> T {
|
fn buffer_ref_mut(&mut self) -> &mut BufferRef<'buffer> {
|
||||||
self.editor.with_buffer_mut(f)
|
self.editor.buffer_ref_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cursor(&self) -> Cursor {
|
fn cursor(&self) -> Cursor {
|
||||||
|
|
@ -408,7 +408,9 @@ impl<'a, 'b> Edit for SyntaxEditor<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b, 'c> BorrowedWithFontSystem<'c, SyntaxEditor<'a, 'b>> {
|
impl<'font_system, 'syntax_system, 'buffer>
|
||||||
|
BorrowedWithFontSystem<'font_system, SyntaxEditor<'syntax_system, 'buffer>>
|
||||||
|
{
|
||||||
/// Load text from a file, and also set syntax to the best option
|
/// Load text from a file, and also set syntax to the best option
|
||||||
///
|
///
|
||||||
/// ## Errors
|
/// ## Errors
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,16 @@ use modit::{Event, Key, Parser, TextObject, WordIter};
|
||||||
use unicode_segmentation::UnicodeSegmentation;
|
use unicode_segmentation::UnicodeSegmentation;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Action, AttrsList, BorrowedWithFontSystem, Buffer, Change, Color, Cursor, Edit, FontSystem,
|
Action, AttrsList, BorrowedWithFontSystem, BufferRef, Change, Color, Cursor, Edit, FontSystem,
|
||||||
Motion, Selection, SyntaxEditor, SyntaxTheme,
|
Motion, Selection, SyntaxEditor, SyntaxTheme,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use modit::{ViMode, ViParser};
|
pub use modit::{ViMode, ViParser};
|
||||||
|
|
||||||
fn undo_2_action<E: Edit>(editor: &mut E, action: cosmic_undo_2::Action<&Change>) {
|
fn undo_2_action<'buffer, E: Edit<'buffer>>(
|
||||||
|
editor: &mut E,
|
||||||
|
action: cosmic_undo_2::Action<&Change>,
|
||||||
|
) {
|
||||||
match action {
|
match action {
|
||||||
cosmic_undo_2::Action::Do(change) => {
|
cosmic_undo_2::Action::Do(change) => {
|
||||||
editor.apply_change(change);
|
editor.apply_change(change);
|
||||||
|
|
@ -24,7 +27,7 @@ fn undo_2_action<E: Edit>(editor: &mut E, action: cosmic_undo_2::Action<&Change>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn finish_change<E: Edit>(
|
fn finish_change<'buffer, E: Edit<'buffer>>(
|
||||||
editor: &mut E,
|
editor: &mut E,
|
||||||
commands: &mut cosmic_undo_2::Commands<Change>,
|
commands: &mut cosmic_undo_2::Commands<Change>,
|
||||||
changed: &mut bool,
|
changed: &mut bool,
|
||||||
|
|
@ -42,7 +45,7 @@ fn finish_change<E: Edit>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search<E: Edit>(editor: &mut E, value: &str, forwards: bool) -> bool {
|
fn search<'buffer, E: Edit<'buffer>>(editor: &mut E, value: &str, forwards: bool) -> bool {
|
||||||
let mut cursor = editor.cursor();
|
let mut cursor = editor.cursor();
|
||||||
let start_line = cursor.line;
|
let start_line = cursor.line;
|
||||||
if forwards {
|
if forwards {
|
||||||
|
|
@ -94,7 +97,7 @@ fn search<E: Edit>(editor: &mut E, value: &str, forwards: bool) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
fn select_in<E: Edit>(editor: &mut E, start_c: char, end_c: char, include: bool) {
|
fn select_in<'buffer, E: Edit<'buffer>>(editor: &mut E, start_c: char, end_c: char, include: bool) {
|
||||||
// Find the largest encompasing object, or if there is none, find the next one.
|
// Find the largest encompasing object, or if there is none, find the next one.
|
||||||
let cursor = editor.cursor();
|
let cursor = editor.cursor();
|
||||||
let (start, end) = editor.with_buffer(|buffer| {
|
let (start, end) = editor.with_buffer(|buffer| {
|
||||||
|
|
@ -156,8 +159,8 @@ fn select_in<E: Edit>(editor: &mut E, start_c: char, end_c: char, include: bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ViEditor<'a, 'b> {
|
pub struct ViEditor<'syntax_system, 'buffer> {
|
||||||
editor: SyntaxEditor<'a, 'b>,
|
editor: SyntaxEditor<'syntax_system, 'buffer>,
|
||||||
parser: ViParser,
|
parser: ViParser,
|
||||||
passthrough: bool,
|
passthrough: bool,
|
||||||
registers: BTreeMap<char, (Selection, String)>,
|
registers: BTreeMap<char, (Selection, String)>,
|
||||||
|
|
@ -166,8 +169,8 @@ pub struct ViEditor<'a, 'b> {
|
||||||
changed: bool,
|
changed: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> ViEditor<'a, 'b> {
|
impl<'syntax_system, 'buffer> ViEditor<'syntax_system, 'buffer> {
|
||||||
pub fn new(editor: SyntaxEditor<'a, 'b>) -> Self {
|
pub fn new(editor: SyntaxEditor<'syntax_system, 'buffer>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
editor,
|
editor,
|
||||||
parser: ViParser::new(),
|
parser: ViParser::new(),
|
||||||
|
|
@ -477,13 +480,13 @@ impl<'a, 'b> ViEditor<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b> Edit for ViEditor<'a, 'b> {
|
impl<'syntax_system, 'buffer> Edit<'buffer> for ViEditor<'syntax_system, 'buffer> {
|
||||||
fn with_buffer<F: FnOnce(&Buffer) -> T, T>(&self, f: F) -> T {
|
fn buffer_ref(&self) -> &BufferRef<'buffer> {
|
||||||
self.editor.with_buffer(f)
|
self.editor.buffer_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_buffer_mut<F: FnOnce(&mut Buffer) -> T, T>(&mut self, f: F) -> T {
|
fn buffer_ref_mut(&mut self) -> &mut BufferRef<'buffer> {
|
||||||
self.editor.with_buffer_mut(f)
|
self.editor.buffer_ref_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cursor(&self) -> Cursor {
|
fn cursor(&self) -> Cursor {
|
||||||
|
|
@ -1098,7 +1101,9 @@ impl<'a, 'b> Edit for ViEditor<'a, 'b> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b, 'c> BorrowedWithFontSystem<'c, ViEditor<'a, 'b>> {
|
impl<'font_system, 'syntax_system, 'buffer>
|
||||||
|
BorrowedWithFontSystem<'font_system, ViEditor<'syntax_system, 'buffer>>
|
||||||
|
{
|
||||||
/// Load text from a file, and also set syntax to the best option
|
/// Load text from a file, and also set syntax to the best option
|
||||||
#[cfg(feature = "std")]
|
#[cfg(feature = "std")]
|
||||||
pub fn load_text<P: AsRef<std::path::Path>>(
|
pub fn load_text<P: AsRef<std::path::Path>>(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue