mirror of
https://github.com/storytold/wordcraft.git
synced 2026-11-09 03:39:51 -06:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e49aaf0072 |
+2
-2
File diff suppressed because one or more lines are too long
@@ -58,6 +58,23 @@ mod tests {
|
||||
assert!(t.rows.iter().all(|r| r.len() <= 64), "a row grew past the column cap");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn insert_covered_skips_full_rows_without_walking_them() {
|
||||
// 50,000 spanning cells over a 50,000-cell row: each walked the row below to its grid
|
||||
// column before finding it full (billions of steps). A full row is now skipped at once.
|
||||
let n = 50_000;
|
||||
let mut t = FTable {
|
||||
rows: vec![vec![Cell { rowspan: 2, ..Default::default() }; n], vec![Cell::default(); n]],
|
||||
widths: Vec::new(),
|
||||
borderless: false,
|
||||
};
|
||||
let start = std::time::Instant::now();
|
||||
t.insert_covered();
|
||||
assert!(start.elapsed() < std::time::Duration::from_secs(10), "{:?}", start.elapsed());
|
||||
assert_eq!(t.rows[1].len(), n, "a full row takes no covered cell");
|
||||
assert!(t.rows[1].iter().all(|c| !c.covered));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn base64_round_trip() {
|
||||
for data in [&b""[..], b"f", b"fo", b"foo", b"foob", b"fooba", b"foobar", &[0, 255, 128, 7]] {
|
||||
|
||||
@@ -418,6 +418,11 @@ impl FTable {
|
||||
return;
|
||||
}
|
||||
let Some(row) = self.rows.get_mut(r + k) else { break };
|
||||
// A full row takes no covered cell: checked before it is walked, so a
|
||||
// wide row isn't scanned for every span above it.
|
||||
if row.len() >= 64 {
|
||||
continue;
|
||||
}
|
||||
// Find the index in that row at grid column `g`.
|
||||
let mut x = 0usize;
|
||||
let mut at = row.len();
|
||||
@@ -428,9 +433,7 @@ impl FTable {
|
||||
}
|
||||
x += cc.colspan.clamp(1, 63) as usize;
|
||||
}
|
||||
if row.len() < 64 {
|
||||
row.insert(at, Cell { colspan: span as u32, covered: true, ..Default::default() });
|
||||
}
|
||||
row.insert(at, Cell { colspan: span as u32, covered: true, ..Default::default() });
|
||||
}
|
||||
}
|
||||
g += span;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::balloons::over_balloon;
|
||||
use super::links::{field_showing_code, for_launcher, is_followable_link, is_generated_bookmark_link, link_under};
|
||||
use super::links::{field_showing_code, is_followable_link, is_generated_bookmark_link, link_under};
|
||||
use super::navigation::page_at;
|
||||
use super::story::{enters_header_footer, in_text_box, part_kind, text_box_host};
|
||||
use super::{CanvasState, DocLayout, PartKind, Pos, Pos2, Rect, StoryRef, Ui, WordApp, json};
|
||||
@@ -335,7 +335,7 @@ fn handle_primary_press(
|
||||
let _ = app.run("select.collapse", json!({}));
|
||||
}
|
||||
} else if is_followable_link(&link) {
|
||||
app.canvas.open_url = Some(for_launcher(&link));
|
||||
app.canvas.open_url = Some(link);
|
||||
} else {
|
||||
app.status(tl!("Only web (http, https) and email (mailto) links can be followed"));
|
||||
}
|
||||
|
||||
@@ -48,19 +48,3 @@ pub(super) fn is_generated_bookmark_link(link: &str) -> bool {
|
||||
pub(super) fn is_followable_link(url: &str) -> bool {
|
||||
wordcraft_doc::link::is_web_or_mail_link(url)
|
||||
}
|
||||
|
||||
/// `url` as it is handed to the system to open: the characters a Windows command line acts on
|
||||
/// (`|`, `<`, `>`, `(`, `)`, `^`, `!`, `"`, and spaces) percent-encoded, which a browser reads the
|
||||
/// same. Under WSL the browser crate starts the link through `cmd.exe /c start`, escaping only
|
||||
/// `^` and `&`, so `https://x/a|calc` would run `calc`. `&` is left alone: it separates a query's
|
||||
/// fields, and that launcher escapes it.
|
||||
pub(super) fn for_launcher(url: &str) -> String {
|
||||
let mut out = String::with_capacity(url.len());
|
||||
for c in url.chars() {
|
||||
match c {
|
||||
'|' | '<' | '>' | '(' | ')' | '^' | '!' | '"' | ' ' => out.push_str(&format!("%{:02X}", c as u32)),
|
||||
c => out.push(c),
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
@@ -2646,17 +2646,6 @@ fn only_web_and_email_links_are_followed() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn followed_links_reach_the_launcher_without_command_line_syntax() {
|
||||
use super::links::for_launcher;
|
||||
assert_eq!(for_launcher("https://x.example/a|calc"), "https://x.example/a%7Ccalc");
|
||||
assert_eq!(for_launcher("https://x.example/a^b<c>d(e)f!g\"h i"), "https://x.example/a%5Eb%3Cc%3Ed%28e%29f%21g%22h%20i");
|
||||
// Ordinary links, queries and existing escapes are unchanged.
|
||||
for ok in ["https://example.com/a?b=1&c=2#d", "mailto:someone@example.com", "https://example.com/caf%C3%A9"] {
|
||||
assert_eq!(for_launcher(ok), ok);
|
||||
}
|
||||
}
|
||||
|
||||
/// Ctrl+click on a link to a bookmark puts the caret at the bookmark's start, as Word does;
|
||||
/// only Go To selects the bookmark's text (#1236).
|
||||
#[test]
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user