Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

fix(web): underlines appearing in random spots

Elijah Potteracc2f8b16d43
diff --git a/harper-core/src/lib.rs b/harper-core/src/lib.rs
index 1075de15d..c7f25c61c 100644
--- a/harper-core/src/lib.rs
+++ b/harper-core/src/lib.rs
@@ -61,3 +61,31 @@ pub fn remove_overlaps(lints: &mut Vec<Lint>) {
lints.remove_indices(remove_indices);
}
+
+#[cfg(test)]
+mod tests {
+ use crate::{
+ linting::{LintGroup, LintGroupConfig, Linter},
+ remove_overlaps, Document, FullDictionary,
+ };
+
+ #[test]
+ fn keeps_space_lint() {
+ let doc = Document::new_plain_english_curated("Ths tet");
+
+ let lint_config = LintGroupConfig {
+ spell_check: Some(true),
+ spaces: Some(true),
+ ..LintGroupConfig::none()
+ };
+ let mut linter = LintGroup::new(lint_config, FullDictionary::curated());
+
+ let mut lints = linter.lint(&doc);
+
+ dbg!(&lints);
+ remove_overlaps(&mut lints);
+ dbg!(&lints);
+
+ assert_eq!(lints.len(), 3);
+ }
+}
diff --git a/harper-core/src/linting/lint_group.rs b/harper-core/src/linting/lint_group.rs
index 9e1f0a1c9..b68e70b09 100644
--- a/harper-core/src/linting/lint_group.rs
+++ b/harper-core/src/linting/lint_group.rs
@@ -36,6 +36,16 @@ macro_rules! create_lint_group_config {
}
impl LintGroupConfig {
+ /// Creates a config with all lints disabled.
+ pub fn none() -> Self{
+ Self {
+ $(
+ [<$linter:snake>]: Some(false),
+ )*
+ spell_check: Some(false)
+ }
+ }
+
/// Fills the [`None`] values in the configuration with the default values.
pub fn fill_default_values(&mut self){
$(
diff --git a/harper-core/src/span.rs b/harper-core/src/span.rs
index 6e71e088c..4fdac1d08 100644
--- a/harper-core/src/span.rs
+++ b/harper-core/src/span.rs
@@ -37,7 +37,7 @@ impl Span {
}
pub fn overlaps_with(&self, other: Self) -> bool {
- self.start.max(other.start) <= self.end.min(other.end)
+ (self.start < other.end) && (other.start < self.end)
}
/// Get the associated content. Will return [`None`] if any aspect is
@@ -130,5 +130,7 @@ mod tests {
assert!(Span::new(0, 5).overlaps_with(Span::new(2, 3)));
assert!(Span::new(0, 5).overlaps_with(Span::new(4, 5)));
assert!(Span::new(0, 5).overlaps_with(Span::new(4, 4)));
+
+ assert!(!Span::new(0, 3).overlaps_with(Span::new(3, 5)));
}
}
diff --git a/packages/web/src/lib/Underlines.svelte b/packages/web/src/lib/Underlines.svelte
index bb9b2825e..0ea09f36a 100644
--- a/packages/web/src/lib/Underlines.svelte
+++ b/packages/web/src/lib/Underlines.svelte
@@ -27,10 +27,6 @@
});
function reOrgString(text: string): (string | undefined)[] {
- if (text.trim().length == 0) {
- return [''];
- }
-
let output: (string | undefined)[] = [];
for (let chunk of text.replaceAll(' ', '\u00A0').split('\n')) {
@@ -104,7 +100,7 @@
{#if chunk == null}
<br />
{:else if typeof chunk == 'string'}
- <span class="">{chunk}</span>
+ <span class="whitespace-pre">{chunk}</span>
{:else}
<span class="pointer-events-auto" style={`margin-right: -4px;`}>
<button