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 = "367ba7e0db5f1b890e3563773cf96c0dd49aac2c"
rev = "9797e78ad4664ae5055e8dab6067e40b215f6b3e"

[patch.crates-io.impl-tools-lib]
git = "https://github.com/kas-gui/impl-tools.git"
Expand Down
23 changes: 7 additions & 16 deletions crates/kas-core/src/text/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,24 +311,15 @@ impl ConfiguredDisplay {

/// Get the base directionality of the text
///
/// This does not require that the text is prepared.
/// This returns the direction inferred during run-breaking if available,
/// falling back to [`Direction::text_is_rtl`].
#[inline]
pub fn text_is_rtl(&self, text: &str) -> bool {
let cached_is_rtl = match self.line_is_rtl(0) {
Ok(None) => Some(self.direction == Direction::Rtl),
Ok(Some(is_rtl)) => Some(is_rtl),
Err(NotReady) => None,
};

#[cfg(not(debug_assertions))]
if let Some(cached) = cached_is_rtl {
return cached;
}

let is_rtl = self.unchecked_display().text_is_rtl(text, self.direction());
if let Some(cached) = cached_is_rtl {
debug_assert_eq!(cached, is_rtl);
if self.status >= Status::ResizeLevelRuns {
self.display.text_is_rtl()
} else {
self.direction.text_is_rtl(text)
}
is_rtl
}

/// Get the status of preparation
Expand Down
4 changes: 4 additions & 0 deletions crates/kas-widgets/src/edit/edit_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ impl<A: 'static> EditBox<StringGuard<A>> {

impl<G: EditGuard, H: Highlighter> EditBox<G, H> {
/// Set the base text direction (inline)
///
/// If [`Direction::Auto`] or [`Direction::AutoRtl`] is used, the direction
/// will be updated on edit to persist the last used text direction to
/// non-directional content.
#[inline]
pub fn with_direction(mut self, direction: Direction) -> Self {
self.inner.set_direction(direction);
Expand Down
4 changes: 4 additions & 0 deletions crates/kas-widgets/src/edit/edit_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ impl<A: 'static> EditBoxCore<DefaultGuard<A>> {

impl<G: EditGuard, H: Highlighter> EditBoxCore<G, H> {
/// Set the base text direction
///
/// If [`Direction::Auto`] or [`Direction::AutoRtl`] is used, the direction
/// will be updated on edit to persist the last used text direction to
/// non-directional content.
#[inline]
pub fn set_direction(&mut self, direction: Direction) {
self.editor.set_direction(direction);
Expand Down
39 changes: 19 additions & 20 deletions crates/kas-widgets/src/edit/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ impl<H: Highlighter> Component<H> {
}

/// Set the base text direction
///
/// If [`Direction::Auto`] or [`Direction::AutoRtl`] is used, the direction
/// will be updated on edit to persist the last used text direction to
/// non-directional content.
#[inline]
pub fn set_direction(&mut self, direction: Direction) {
self.0.part.set_direction(direction);
Expand Down Expand Up @@ -370,6 +374,10 @@ impl Part {
}

/// Set the base text direction
///
/// If [`Direction::Auto`] or [`Direction::AutoRtl`] is used, the direction
/// will be updated on edit to persist the last used text direction to
/// non-directional content.
#[inline]
pub fn set_direction(&mut self, direction: Direction) {
self.direction = direction;
Expand Down Expand Up @@ -398,28 +406,11 @@ impl Part {

/// Get the base directionality of the text
///
/// This does not require that the text is prepared.
/// [`Self::configure`] should be called before this method.
#[inline]
pub fn text_is_rtl(&self) -> bool {
let mut cached_is_rtl = None;
if self.status >= Status::Wrapped {
cached_is_rtl = match self.display.line_is_rtl(0) {
None => Some(self.direction == Direction::Rtl),
Some(is_rtl) => Some(is_rtl),
};
};

#[cfg(not(debug_assertions))]
if let Some(cached) = cached_is_rtl {
return cached;
}

let text = self.as_str();
let is_rtl = self.display.text_is_rtl(text, self.direction);
if let Some(cached) = cached_is_rtl {
debug_assert_eq!(cached, is_rtl);
}
is_rtl
debug_assert!(self.status >= Status::ResizeLevelRuns);
self.display.text_is_rtl()
}

/// Access the cursor index / selection range
Expand Down Expand Up @@ -484,6 +475,14 @@ impl Part {
}

part.status = Status::LevelRuns;

if part.direction.is_auto() {
part.direction = if dbg!(part.display.text_is_rtl()) {
Direction::AutoRtl
} else {
Direction::Auto
};
}
}

if self.status < Status::LevelRuns {
Expand Down