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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ resolver = "2"

[patch.crates-io.kas-text]
git = "https://github.com/kas-gui/kas-text.git"
rev = "a087ae3c083fb8e7f73282514b556ecc9083c95a"
rev = "367ba7e0db5f1b890e3563773cf96c0dd49aac2c"

[patch.crates-io.impl-tools-lib]
git = "https://github.com/kas-gui/impl-tools.git"
Expand Down
8 changes: 3 additions & 5 deletions crates/kas-core/src/text/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,12 +471,9 @@ impl ConfiguredDisplay {
/// using the size reported by [`Self::bounding_box`]. Note that while
/// vertical alignment is untouched by this method, text is never aligned
/// above the top (the first y-component is never negative).
#[inline]
pub fn ensure_no_left_overhang(&mut self) {
if let Ok((tl, _)) = self.bounding_box()
&& tl.0 < 0.0
{
self.display.apply_offset(kas_text::Vec2(-tl.0, 0.0));
}
self.display.ensure_non_negative_alignment();
}

/// Get the size of the required bounding box
Expand Down Expand Up @@ -514,6 +511,7 @@ impl ConfiguredDisplay {

/// Find the line containing text `index`
///
/// Returns the line number and the text-range of the line.
/// See [`TextDisplay::find_line`].
#[inline]
pub fn find_line(
Expand Down
21 changes: 11 additions & 10 deletions crates/kas-core/src/text/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

//! Tools for text selection

use super::ConfiguredDisplay;
use kas_macros::autoimpl;
use std::ops::Range;
use unicode_segmentation::UnicodeSegmentation;
Expand Down Expand Up @@ -182,7 +181,15 @@ impl SelectionHelper {
///
/// The selection is expanded by words or lines (if `lines`). Line expansion
/// requires that text has been prepared (see [`Text::prepare`][super::Text::prepare]).
pub fn expand(&mut self, text: &str, display: &ConfiguredDisplay, lines: bool) {
///
/// Input `line_range` should map a text index to the range of the enclosing
/// line (if available).
pub fn expand(
&mut self,
text: &str,
line_range: &dyn Fn(usize) -> Option<std::ops::Range<usize>>,
lines: bool,
) {
let mut range = self.edit..self.anchor;
if range.start > range.end {
std::mem::swap(&mut range.start, &mut range.end);
Expand All @@ -207,14 +214,8 @@ impl SelectionHelper {
})
.unwrap_or(text.len());
} else {
start = match display.find_line(range.start) {
Ok(Some(r)) => r.1.start,
_ => 0,
};
end = match display.find_line(range.end) {
Ok(Some(r)) => r.1.end,
_ => text.len(),
};
start = line_range(range.start).map(|r| r.start).unwrap_or(0);
end = line_range(range.end).map(|r| r.end).unwrap_or(text.len());
}

if self.edit < self.sel {
Expand Down
18 changes: 9 additions & 9 deletions crates/kas-widgets/src/edit/edit_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use crate::{ScrollBar, ScrollBarMsg};
use kas::event::Scroll;
use kas::event::components::ScrollComponent;
use kas::prelude::*;
use kas::theme::{FrameStyle, TextClass};
use kas::text::Direction;
use kas::theme::FrameStyle;
use std::fmt::{Debug, Display};
use std::str::FromStr;

Expand Down Expand Up @@ -391,6 +392,13 @@ impl<A: 'static> EditBox<StringGuard<A>> {
}

impl<G: EditGuard, H: Highlighter> EditBox<G, H> {
/// Set the base text direction (inline)
#[inline]
pub fn with_direction(mut self, direction: Direction) -> Self {
self.inner.set_direction(direction);
self
}

/// Set the initial text (inline)
///
/// This method should only be used on a new `EditBox`.
Expand Down Expand Up @@ -420,14 +428,6 @@ impl<G: EditGuard, H: Highlighter> EditBox<G, H> {
self
}

/// Set the text class used
#[inline]
#[must_use]
pub fn with_class(mut self, class: TextClass) -> Self {
self.inner = self.inner.with_class(class);
self
}

/// Adjust the height allocation
#[inline]
pub fn set_lines(&mut self, min_lines: f32, ideal_lines: f32) {
Expand Down
17 changes: 8 additions & 9 deletions crates/kas-widgets/src/edit/edit_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::edit::highlight::{Highlighter, Plain};
use kas::event::CursorIcon;
use kas::messages::{ReplaceSelectedText, SetValueText};
use kas::prelude::*;
use kas::text::Direction;
use kas::theme::{Background, TextClass};
use std::ops::Deref;

Expand Down Expand Up @@ -83,7 +84,7 @@ mod EditBoxCore {
fn size_rules(&mut self, cx: &mut SizeCx, axis: AxisInfo) -> SizeRules {
let (min, mut ideal): (i32, i32);
if axis.is_horizontal() {
let dpem = cx.dpem(self.class());
let dpem = cx.dpem(TextClass::Editor);
min = (self.width.0 * dpem).cast_ceil();
ideal = (self.width.1 * dpem).cast_ceil();
} else if let Some(width) = axis.other() {
Expand Down Expand Up @@ -303,6 +304,12 @@ impl<A: 'static> EditBoxCore<DefaultGuard<A>> {
}

impl<G: EditGuard, H: Highlighter> EditBoxCore<G, H> {
/// Set the base text direction
#[inline]
pub fn set_direction(&mut self, direction: Direction) {
self.editor.set_direction(direction);
}

/// Set the initial text (inline)
///
/// This method should only be used on a new `EditBoxCore`.
Expand Down Expand Up @@ -336,14 +343,6 @@ impl<G: EditGuard, H: Highlighter> EditBoxCore<G, H> {
self
}

/// Set the text class used
#[inline]
#[must_use]
pub fn with_class(mut self, class: TextClass) -> Self {
self.editor.set_class(class);
self
}

/// Adjust the height allocation
#[inline]
pub fn set_lines(&mut self, min_lines: f32, ideal_lines: f32) {
Expand Down
Loading