From 4adc4b08ba0a892d9369fad83fb52bc36f8109ba Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 27 Apr 2026 15:32:09 -0700 Subject: [PATCH] Add a test for global keypress with ACE editor focused This is a regression test for https://github.com/rust-lang/mdBook/issues/3064. --- tests/gui/books/editor/book.toml | 6 ++++++ tests/gui/books/editor/src/SUMMARY.md | 4 ++++ tests/gui/books/editor/src/chapter_1.md | 7 +++++++ tests/gui/books/editor/src/chapter_2.md | 1 + tests/gui/editor-keypress.goml | 23 +++++++++++++++++++++++ 5 files changed, 41 insertions(+) create mode 100644 tests/gui/books/editor/book.toml create mode 100644 tests/gui/books/editor/src/SUMMARY.md create mode 100644 tests/gui/books/editor/src/chapter_1.md create mode 100644 tests/gui/books/editor/src/chapter_2.md create mode 100644 tests/gui/editor-keypress.goml diff --git a/tests/gui/books/editor/book.toml b/tests/gui/books/editor/book.toml new file mode 100644 index 00000000..2af92d4c --- /dev/null +++ b/tests/gui/books/editor/book.toml @@ -0,0 +1,6 @@ +[book] +title = "editor" +language = "en" + +[output.html.playground] +editable = true diff --git a/tests/gui/books/editor/src/SUMMARY.md b/tests/gui/books/editor/src/SUMMARY.md new file mode 100644 index 00000000..fa67cf3e --- /dev/null +++ b/tests/gui/books/editor/src/SUMMARY.md @@ -0,0 +1,4 @@ +# Summary + +- [Chapter 1](./chapter_1.md) +- [Chapter 2](./chapter_2.md) diff --git a/tests/gui/books/editor/src/chapter_1.md b/tests/gui/books/editor/src/chapter_1.md new file mode 100644 index 00000000..8982f7d3 --- /dev/null +++ b/tests/gui/books/editor/src/chapter_1.md @@ -0,0 +1,7 @@ +# Chapter 1 + +```rust,editable +fn main() { + println!("Hello, world!"); +} +``` diff --git a/tests/gui/books/editor/src/chapter_2.md b/tests/gui/books/editor/src/chapter_2.md new file mode 100644 index 00000000..7ebb5961 --- /dev/null +++ b/tests/gui/books/editor/src/chapter_2.md @@ -0,0 +1 @@ +# Chapter 2 diff --git a/tests/gui/editor-keypress.goml b/tests/gui/editor-keypress.goml new file mode 100644 index 00000000..6b1a96fc --- /dev/null +++ b/tests/gui/editor-keypress.goml @@ -0,0 +1,23 @@ +// Tests for global keypress handlers when ACE editor is in focus. +// See https://github.com/rust-lang/mdBook/issues/3064 + +go-to: |DOC_PATH| + "editor/chapter_1.html" + +click: ".ace_editor" +press-key: "s" +// Wait briefly to allow any event handlers triggered by the keypress to run. +// Otherwise there is a race here since the wrapper is already display:none. +wait-for: 200 +wait-for-css: ("#mdbook-search-wrapper", {"display": "none"}) + +press-key: "?" +wait-for: 200 +wait-for-css: ("#mdbook-help-container", {"display": "flex"}) + +// Make sure arrow keys don"t navigate. +press-key: "ArrowRight" +wait-for: 200 +assert-window-property: ({"location": |DOC_PATH| + "editor/chapter_1.html"}) +press-key: "ArrowLeft" +wait-for: 200 +assert-window-property: ({"location": |DOC_PATH| + "editor/chapter_1.html"})