Skip to content

Commit

Permalink
feat: Update freya
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Oct 5, 2024
1 parent 090b33a commit a838ae5
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 68 deletions.
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ edition = "2021"
dioxus-sdk = { git = "https://github.com/DioxusLabs/sdk", rev = "57ab3fa972c6d4a7acc25e82a0aafc3ff9e63403" }

[dependencies]
freya-node-state = { git = "https://github.com/marc2332/freya", rev = "1b1a24a84e2a80bffc3d439ae023cb9a812ec1b1" }
freya = { git = "https://github.com/marc2332/freya", rev = "1b1a24a84e2a80bffc3d439ae023cb9a812ec1b1" }
freya-hooks = { git = "https://github.com/marc2332/freya", rev = "1b1a24a84e2a80bffc3d439ae023cb9a812ec1b1" }
freya-node-state = { git = "https://github.com/marc2332/freya", rev = "523a9d98339c356d4edc43fec7f87ba35c3ffe59" }
freya = { git = "https://github.com/marc2332/freya", rev = "523a9d98339c356d4edc43fec7f87ba35c3ffe59" }
freya-hooks = { git = "https://github.com/marc2332/freya", rev = "523a9d98339c356d4edc43fec7f87ba35c3ffe59" }

dioxus-radio = "0.2.4"
dioxus = "0.5"
Expand Down
4 changes: 2 additions & 2 deletions src/components/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn EditorTab(
is_edited: bool,
) -> Element {
let mut status = use_signal(ButtonStatus::default);
let theme = use_get_theme();
let theme = use_applied_theme!(None, button);
let platform = use_platform();

use_drop(move || {
Expand All @@ -35,7 +35,7 @@ pub fn EditorTab(
ButtonStatus::Hovering => "rgb(30, 30, 30)",
ButtonStatus::Idle => "transparent",
};
let color = theme.button.font_theme.color;
let color = theme.font_theme.color;
let selected_color = if is_selected {
"rgb(60, 60, 60)"
} else {
Expand Down
26 changes: 8 additions & 18 deletions src/hooks/use_edit.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use dioxus::dioxus_core::AttributeValue;
use dioxus_use_computed::hooks::use_computed;
use freya::core::prelude::{EventMessage, TextGroupMeasurement};

use crate::tabs::editor::AppStateEditorUtils;
Expand Down Expand Up @@ -172,9 +171,9 @@ pub fn use_edit(radio: &RadioAppState, panel_index: usize, tab_index: usize) ->
let platform = use_platform();
let mut cursor_receiver_task = use_signal::<Option<Task>>(|| None);

let cursor_reference = use_computed((panel_index, tab_index), {
let cursor_reference = use_memo(use_reactive(&(panel_index, tab_index), {
to_owned![radio];
move || {
move |(panel_index, tab_index)| {
if let Some(cursor_receiver_task) = cursor_receiver_task.write_unchecked().take() {
cursor_receiver_task.cancel();
}
Expand All @@ -200,16 +199,15 @@ pub fn use_edit(radio: &RadioAppState, panel_index: usize, tab_index: usize) ->
id,
);

// Only update if it's actually different
if editor_tab.editor.cursor != new_cursor {
// Only update and clear the selection if the cursor has changed
if editor_tab.editor.cursor() != new_cursor {
let editor_tab = app_state.editor_tab_mut(panel_index, tab_index);
*editor_tab.editor.cursor_mut() = new_cursor;

if let TextDragging::FromCursorToPoint { cursor: from, .. } =
dragging()
&*dragging.read()
{
let to = editor_tab.editor.cursor_pos();
editor_tab.editor.set_selection((from, to));
editor_tab.editor.set_selection((*from, to));
} else {
editor_tab.editor.clear_selection();
}
Expand All @@ -218,34 +216,26 @@ pub fn use_edit(radio: &RadioAppState, panel_index: usize, tab_index: usize) ->
// Update the text selections calculated by the layout
CursorLayoutResponse::TextSelection { from, to, id } => {
let mut app_state = radio.write();
let editor_tab = app_state.editor_tab(panel_index, tab_index);
let editor_tab = app_state.editor_tab_mut(panel_index, tab_index);

let current_cursor = editor_tab.editor.cursor().clone();
let current_selection = editor_tab.editor.get_selection();

let maybe_new_cursor = editor_tab.editor.measure_new_cursor(to, id);
let (from, to) = (
editor_tab.editor.utf16_cu_to_char(from),
editor_tab.editor.utf16_cu_to_char(to),
);
let maybe_new_selection =
editor_tab.editor.measure_new_selection(from, to, id);

// Update the text selection if it has changed
if let Some(current_selection) = current_selection {
if current_selection != maybe_new_selection {
let editor_tab =
app_state.editor_tab_mut(panel_index, tab_index);
editor_tab.editor.set_selection(maybe_new_selection);
}
} else {
let editor_tab = app_state.editor_tab_mut(panel_index, tab_index);
editor_tab.editor.set_selection(maybe_new_selection);
}

// Update the cursor if it has changed
if current_cursor != maybe_new_cursor {
let editor_tab = app_state.editor_tab_mut(panel_index, tab_index);
*editor_tab.editor.cursor_mut() = maybe_new_cursor;
}
}
Expand All @@ -257,7 +247,7 @@ pub fn use_edit(radio: &RadioAppState, panel_index: usize, tab_index: usize) ->

cursor_reference
}
});
}));

UseEdit {
radio: *radio,
Expand Down
7 changes: 4 additions & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{borrow::Cow, ops::Range};

use fxhash::FxHashMap;
use ropey::Rope;
use smallvec::SmallVec;

Expand Down Expand Up @@ -60,16 +61,16 @@ pub type SyntaxLine = SmallVec<[(SyntaxType, TextNode); 4]>;

#[derive(Default)]
pub struct SyntaxBlocks {
blocks: Vec<SyntaxLine>,
blocks: FxHashMap<usize, SyntaxLine>,
}

impl SyntaxBlocks {
pub fn push_line(&mut self, line: SyntaxLine) {
self.blocks.push(line);
self.blocks.insert(self.len(), line);
}

pub fn get_line(&self, line: usize) -> &[(SyntaxType, TextNode)] {
&self.blocks[line]
self.blocks.get(&line).unwrap()
}

pub fn len(&self) -> usize {
Expand Down
Loading

0 comments on commit a838ae5

Please sign in to comment.