vastly improved selection system
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
use cagire_ratatui::Editor;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
@@ -50,14 +52,36 @@ pub struct EditorContext {
|
||||
pub step: usize,
|
||||
pub focus: Focus,
|
||||
pub editor: Editor,
|
||||
pub copied_step: Option<CopiedStep>,
|
||||
pub selection_anchor: Option<usize>,
|
||||
pub copied_steps: Option<CopiedSteps>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct CopiedStep {
|
||||
#[derive(Clone)]
|
||||
pub struct CopiedSteps {
|
||||
pub bank: usize,
|
||||
pub pattern: usize,
|
||||
pub step: usize,
|
||||
pub steps: Vec<CopiedStepData>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct CopiedStepData {
|
||||
pub script: String,
|
||||
pub active: bool,
|
||||
pub source: Option<usize>,
|
||||
pub original_index: usize,
|
||||
}
|
||||
|
||||
impl EditorContext {
|
||||
pub fn selection_range(&self) -> Option<RangeInclusive<usize>> {
|
||||
let anchor = self.selection_anchor?;
|
||||
let a = anchor.min(self.step);
|
||||
let b = anchor.max(self.step);
|
||||
Some(a..=b)
|
||||
}
|
||||
|
||||
pub fn clear_selection(&mut self) {
|
||||
self.selection_anchor = None;
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for EditorContext {
|
||||
@@ -68,7 +92,8 @@ impl Default for EditorContext {
|
||||
step: 0,
|
||||
focus: Focus::Sequencer,
|
||||
editor: Editor::new(),
|
||||
copied_step: None,
|
||||
selection_anchor: None,
|
||||
copied_steps: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user