use waft_embedder::{TextPosition, TextRange, TextSelection};
use waft_foundation::App;
pub trait TextLayoutMetrics: Copy + 'static {
fn get_line_at_offset(self, app: &mut App, position: TextPosition) -> TextSelection;
fn get_word_boundary(self, app: &mut App, position: TextPosition) -> TextRange;
fn get_text_position_above(self, app: &mut App, position: TextPosition) -> TextPosition;
fn get_text_position_below(self, app: &mut App, position: TextPosition) -> TextPosition;
}
pub fn is_whitespace(code_unit: i32) -> bool {
matches!(
code_unit,
0x9 | 0xA | 0xB | 0xC | 0xD | 0x1C | 0x1D | 0x1E | 0x1F | 0x20 | 0xA0 | 0x1680 | 0x2000 | 0x2001 | 0x2002 | 0x2003 | 0x2004 | 0x2005 | 0x2006 | 0x2007 | 0x2008 | 0x2009 | 0x200A | 0x202F | 0x205F | 0x3000 )
}
pub fn is_line_terminator(code_unit: i32) -> bool {
matches!(
code_unit,
0x0A | 0x0B | 0x0C | 0x0D | 0x85 | 0x2028 | 0x2029 )
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn whitespace_and_line_terminators_match_dart() {
assert!(is_whitespace(0x20));
assert!(is_whitespace(0xA));
assert!(!is_whitespace(b'a' as i32));
assert!(is_line_terminator(0x0A));
assert!(is_line_terminator(0x2028));
assert!(!is_line_terminator(0x20));
}
}