use crate::{ buffer::BufferID, expression::SearchModifier, selection::{Interval, Selection}, selection_functions::types::{ SelectionFunction, SelectionFunctionError, UnparameterisedSelectionFunction, }, state::EditorState, }; pub struct Empty; impl UnparameterisedSelectionFunction for Empty { const NAME: &'static str = "empty"; fn niladic(&self, _es: &EditorState) -> Result { Ok(Selection::empty()) } fn monadic_rank0( &self, _es: &EditorState, _buffer_id: BufferID, _pos: usize, ) -> Result { Ok(Selection::empty()) } fn monadic_rank1( &self, _es: &EditorState, _buffer_id: BufferID, _interval: &Interval, ) -> Result { Ok(Selection::empty()) } } pub struct ReverseEmpty; impl UnparameterisedSelectionFunction for ReverseEmpty { const NAME: &'static str = "reverse_empty"; fn niladic(&self, es: &EditorState) -> Result { Ok(empty_in_buffer(es.current_buffer_id)) } fn monadic_rank0( &self, _es: &EditorState, buffer_id: BufferID, _pos: usize, ) -> Result { Ok(empty_in_buffer(buffer_id)) } fn monadic_rank1( &self, _es: &EditorState, buffer_id: BufferID, _interval: &Interval, ) -> Result { Ok(empty_in_buffer(buffer_id)) } } pub struct SequentialEmpty; impl UnparameterisedSelectionFunction for SequentialEmpty { const NAME: &'static str = "sequential_empty"; fn niladic(&self, _es: &EditorState) -> Result { Err(SelectionFunctionError::NoNiladicForm(";e")) } fn monadic_rank0( &self, _es: &EditorState, buffer_id: BufferID, _pos: usize, ) -> Result { Ok(empty_in_buffer(buffer_id)) } fn monadic_rank1( &self, _es: &EditorState, buffer_id: BufferID, _interval: &Interval, ) -> Result { Ok(empty_in_buffer(buffer_id)) } } pub struct SequentialReverseEmpty; impl UnparameterisedSelectionFunction for SequentialReverseEmpty { const NAME: &'static str = "sequential_reverse_empty"; fn niladic(&self, _es: &EditorState) -> Result { Err(SelectionFunctionError::NoNiladicForm(";'e")) } fn monadic_rank0( &self, _es: &EditorState, buffer_id: BufferID, _pos: usize, ) -> Result { Ok(empty_in_buffer(buffer_id)) } fn monadic_rank1( &self, _es: &EditorState, buffer_id: BufferID, _interval: &Interval, ) -> Result { Ok(empty_in_buffer(buffer_id)) } } pub struct ReverseSequentialEmpty; impl UnparameterisedSelectionFunction for ReverseSequentialEmpty { const NAME: &'static str = "reverse_sequential_empty"; fn niladic(&self, _es: &EditorState) -> Result { Err(SelectionFunctionError::NoNiladicForm("';e")) } fn monadic_rank0( &self, _es: &EditorState, buffer_id: BufferID, _pos: usize, ) -> Result { Ok(empty_in_buffer(buffer_id)) } fn monadic_rank1( &self, _es: &EditorState, buffer_id: BufferID, _interval: &Interval, ) -> Result { Ok(empty_in_buffer(buffer_id)) } } fn empty_in_buffer(buffer_id: BufferID) -> Selection { Selection::Vectors { buffer_id, ranges: Vec::new(), } } pub fn selection_function_empty( es: &EditorState, left: Option<&Selection>, right: Option<&Selection>, search_mod: Option, ) -> Result { match search_mod { None => Empty.apply(&(), es, left, right), Some(SearchModifier::Sequential) => SequentialEmpty.apply(&(), es, left, right), Some(SearchModifier::Reverse) => ReverseEmpty.apply(&(), es, left, right), Some(SearchModifier::SequentialReverse) => { SequentialReverseEmpty.apply(&(), es, left, right) } Some(SearchModifier::ReverseSequential) => { ReverseSequentialEmpty.apply(&(), es, left, right) } } }