Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions src/backend/webgl2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
widgets::hyperlink::HYPERLINK_MODIFIER,
CursorShape,
};
use beamterm_renderer::{
mouse::*, select, CellData, GlyphEffect, SelectionMode, Terminal as Beamterm, Terminal,
};
pub use beamterm_renderer::SelectionMode;
use beamterm_renderer::{mouse::*, select, CellData, GlyphEffect, Terminal as Beamterm, Terminal};
use bitvec::prelude::BitVec;
use compact_str::CompactString;
use ratatui::{
Expand Down Expand Up @@ -45,8 +44,8 @@
cursor_shape: CursorShape,
/// Hyperlink click callback.
hyperlink_callback: Option<HyperlinkCallback>,
/// Whether to use beamterm's internal mouse handler for selection.
default_mouse_handler: bool,
/// Mouse selection mode (enables text selection with mouse).
mouse_selection_mode: Option<SelectionMode>,
/// Measure performance using the `performance` API.
measure_performance: bool,
/// Enable console debugging and introspection API.
Expand Down Expand Up @@ -106,9 +105,23 @@
self
}

/// Enables block-based mouse selection with automatic copy to clipboard on selection.
pub fn enable_mouse_selection(mut self) -> Self {
self.default_mouse_handler = true;
/// Enables mouse selection with automatic copy to clipboard on selection.
///
/// Uses [`SelectionMode::Block`] for rectangular selection.
#[deprecated(
note = "use `enable_mouse_selection_with_mode` instead",
since = "0.3.0"
)]
pub fn enable_mouse_selection(self) -> Self {
self.enable_mouse_selection_with_mode(SelectionMode::default())
}

/// Enables mouse text selection with the specified selection mode.
///
/// - [`SelectionMode::Block`]: Rectangular selection of cells (default)
/// - [`SelectionMode::Linear`]: Linear selection following text flow
pub fn enable_mouse_selection_with_mode(mut self, mode: SelectionMode) -> Self {
self.mouse_selection_mode = Some(mode);
self
}

Expand Down Expand Up @@ -491,7 +504,7 @@
fn create_hyperlink_mouse_handler(
beamterm: &Beamterm,
hyperlink_cells: Rc<RefCell<BitVec>>,
callback: Rc<RefCell<dyn FnMut(&str)>>,

Check warning on line 507 in src/backend/webgl2.rs

View workflow job for this annotation

GitHub Actions / clippy

very complex type used. Consider factoring parts into `type` definitions

warning: very complex type used. Consider factoring parts into `type` definitions --> src/backend/webgl2.rs:507:19 | 507 | callback: Rc<RefCell<dyn FnMut(&str)>>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#type_complexity = note: `#[warn(clippy::type_complexity)]` on by default
cursor_state: Rc<RefCell<bool>>,
) -> Result<TerminalMouseHandler, Error> {
let grid = beamterm.grid();
Expand Down Expand Up @@ -580,8 +593,8 @@
.fallback_glyph(options.fallback_glyph.as_ref().unwrap_or(&" ".into()))
.font_atlas(options.font_atlas.take().unwrap_or_default());

let beamterm = if options.default_mouse_handler {
beamterm.default_mouse_input_handler(SelectionMode::Block, true)
let beamterm = if let Some(mode) = options.mouse_selection_mode {
beamterm.default_mouse_input_handler(mode, true)
} else {
beamterm
};
Expand All @@ -604,7 +617,7 @@
{
// we only update when we have new cell data or if the mouse selection
// handler is enabled (otherwise, we fail to update the visualized selection).
if content.size_hint().1 != Some(0) || self.options.default_mouse_handler {
if content.size_hint().1 != Some(0) || self.options.mouse_selection_mode.is_some() {
self.update_grid(content)?;
}

Expand Down Expand Up @@ -816,7 +829,7 @@
/// A `Debug`-derive friendly convenience wrapper
#[derive(Clone)]
struct HyperlinkCallback {
callback: Rc<RefCell<dyn FnMut(&str)>>,

Check warning on line 832 in src/backend/webgl2.rs

View workflow job for this annotation

GitHub Actions / clippy

very complex type used. Consider factoring parts into `type` definitions

warning: very complex type used. Consider factoring parts into `type` definitions --> src/backend/webgl2.rs:832:15 | 832 | callback: Rc<RefCell<dyn FnMut(&str)>>, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.92.0/index.html#type_complexity
}

impl HyperlinkCallback {
Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ pub use ratatui;
pub use web_sys;

pub use backend::{
canvas::CanvasBackend, cursor::CursorShape, dom::DomBackend, webgl2::WebGl2Backend,
canvas::CanvasBackend,
cursor::CursorShape,
dom::DomBackend,
webgl2::{SelectionMode, WebGl2Backend},
};
pub use render::WebRenderer;
Loading