refactor: extract table selection overlay style
This commit is contained in:
@@ -109,6 +109,32 @@ pub(crate) fn table_col_aux_style(anchor: &TableOverlayAnchor, index: usize) ->
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn table_selection_overlay_style(
|
||||
anchor: &TableOverlayAnchor,
|
||||
selection: &TableSelectionOverlayState,
|
||||
) -> String {
|
||||
match selection.kind {
|
||||
TableSelectionKind::Row => {
|
||||
let row_height = anchor.height / anchor.rows.max(1) as f64;
|
||||
format!(
|
||||
"left:0;top:{:.1}px;width:{:.1}px;height:{:.1}px;",
|
||||
row_height * selection.index as f64,
|
||||
anchor.width,
|
||||
row_height
|
||||
)
|
||||
}
|
||||
TableSelectionKind::Column => {
|
||||
let col_width = anchor.width / anchor.cols.max(1) as f64;
|
||||
format!(
|
||||
"left:{:.1}px;top:0;width:{:.1}px;height:{:.1}px;",
|
||||
col_width * selection.index as f64,
|
||||
col_width,
|
||||
anchor.height
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn floating_toolbar_anchor_from_selection() -> Option<FloatingToolbarAnchor> {
|
||||
let selection = active_editor_text_selection()?;
|
||||
let range = selection.get_range_at(0).ok()?;
|
||||
|
||||
@@ -49,7 +49,8 @@ use editor_runtime::overlays::{
|
||||
close_editor_floating_overlays_if_escape, open_block_menu_overlay, open_image_toolbar_overlay,
|
||||
open_slash_menu_overlay, current_table_overlay_anchor, sync_overlays_on_selection_change,
|
||||
table_col_aux_style, table_overlay_anchor_from_table, table_row_aux_style,
|
||||
toolbar_overlay_locked, try_sync_editor_overlay_state, FloatingToolbarAnchor,
|
||||
table_selection_overlay_style, toolbar_overlay_locked, try_sync_editor_overlay_state,
|
||||
FloatingToolbarAnchor,
|
||||
ImageToolbarAnchor, TableOverlayAnchor, TableSelectionKind, TableSelectionOverlayState,
|
||||
};
|
||||
use editor_runtime::persistence::{
|
||||
@@ -4885,32 +4886,6 @@ fn block_state_from_index(index: usize) -> Option<HoveredBlockState> {
|
||||
})
|
||||
}
|
||||
|
||||
fn table_selection_overlay_style(
|
||||
anchor: &TableOverlayAnchor,
|
||||
selection: &TableSelectionOverlayState,
|
||||
) -> String {
|
||||
match selection.kind {
|
||||
TableSelectionKind::Row => {
|
||||
let row_height = anchor.height / anchor.rows.max(1) as f64;
|
||||
format!(
|
||||
"left:0;top:{:.1}px;width:{:.1}px;height:{:.1}px;",
|
||||
row_height * selection.index as f64,
|
||||
anchor.width,
|
||||
row_height
|
||||
)
|
||||
}
|
||||
TableSelectionKind::Column => {
|
||||
let col_width = anchor.width / anchor.cols.max(1) as f64;
|
||||
format!(
|
||||
"left:{:.1}px;top:0;width:{:.1}px;height:{:.1}px;",
|
||||
col_width * selection.index as f64,
|
||||
col_width,
|
||||
anchor.height
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn prosemirror_node_size(node: &Value) -> Option<u32> {
|
||||
match node.get("type").and_then(Value::as_str) {
|
||||
Some("text") => Some(
|
||||
|
||||
Reference in New Issue
Block a user