Rename feature into Word wrap source code

This commit is contained in:
Guillaume Gomez 2025-02-16 00:34:29 +01:00
parent 38b5bfce24
commit a1471f3aa6
4 changed files with 26 additions and 23 deletions

View file

@ -938,54 +938,54 @@ ul.block, .block li, .block ul {
.example-wrap .line-highlighted[data-nosnippet] { .example-wrap .line-highlighted[data-nosnippet] {
background-color: var(--src-line-number-highlighted-background-color); background-color: var(--src-line-number-highlighted-background-color);
} }
:root.wrap-source-code .example-wrap [data-nosnippet] { :root.word-wrap-source-code .example-wrap [data-nosnippet] {
position: absolute; position: absolute;
left: 0; left: 0;
} }
.wrap-source-code .example-wrap pre > code { .word-wrap-source-code .example-wrap pre > code {
position: relative; position: relative;
word-break: break-all; word-break: break-all;
} }
:root.wrap-source-code .example-wrap pre > code { :root.word-wrap-source-code .example-wrap pre > code {
display: block; display: block;
white-space: pre-wrap; white-space: pre-wrap;
} }
:root.wrap-source-code .example-wrap pre > code * { :root.word-wrap-source-code .example-wrap pre > code * {
word-break: break-all; word-break: break-all;
} }
:root.wrap-source-code .example-wrap.digits-1 pre > code { :root.word-wrap-source-code .example-wrap.digits-1 pre > code {
padding-left: calc( padding-left: calc(
1ch + var(--line-number-padding) * 2 + var(--line-number-right-margin)); 1ch + var(--line-number-padding) * 2 + var(--line-number-right-margin));
} }
:root.wrap-source-code .example-wrap.digits-2 pre > code { :root.word-wrap-source-code .example-wrap.digits-2 pre > code {
padding-left: calc( padding-left: calc(
2ch + var(--line-number-padding) * 2 + var(--line-number-right-margin)); 2ch + var(--line-number-padding) * 2 + var(--line-number-right-margin));
} }
:root.wrap-source-code .example-wrap.digits-3 pre > code { :root.word-wrap-source-code .example-wrap.digits-3 pre > code {
padding-left: calc( padding-left: calc(
3ch + var(--line-number-padding) * 2 + var(--line-number-right-margin)); 3ch + var(--line-number-padding) * 2 + var(--line-number-right-margin));
} }
:root.wrap-source-code .example-wrap.digits-4 pre > code { :root.word-wrap-source-code .example-wrap.digits-4 pre > code {
padding-left: calc( padding-left: calc(
4ch + var(--line-number-padding) * 2 + var(--line-number-right-margin)); 4ch + var(--line-number-padding) * 2 + var(--line-number-right-margin));
} }
:root.wrap-source-code .example-wrap.digits-5 pre > code { :root.word-wrap-source-code .example-wrap.digits-5 pre > code {
padding-left: calc( padding-left: calc(
5ch + var(--line-number-padding) * 2 + var(--line-number-right-margin)); 5ch + var(--line-number-padding) * 2 + var(--line-number-right-margin));
} }
:root.wrap-source-code .example-wrap.digits-6 pre > code { :root.word-wrap-source-code .example-wrap.digits-6 pre > code {
padding-left: calc( padding-left: calc(
6ch + var(--line-number-padding) * 2 + var(--line-number-right-margin)); 6ch + var(--line-number-padding) * 2 + var(--line-number-right-margin));
} }
:root.wrap-source-code .example-wrap.digits-7 pre > code { :root.word-wrap-source-code .example-wrap.digits-7 pre > code {
padding-left: calc( padding-left: calc(
7ch + var(--line-number-padding) * 2 + var(--line-number-right-margin)); 7ch + var(--line-number-padding) * 2 + var(--line-number-right-margin));
} }
:root.wrap-source-code .example-wrap.digits-8 pre > code { :root.word-wrap-source-code .example-wrap.digits-8 pre > code {
padding-left: calc( padding-left: calc(
8ch + var(--line-number-padding) * 2 + var(--line-number-right-margin)); 8ch + var(--line-number-padding) * 2 + var(--line-number-right-margin));
} }
:root.wrap-source-code .example-wrap.digits-9 pre > code { :root.word-wrap-source-code .example-wrap.digits-9 pre > code {
padding-left: calc( padding-left: calc(
9ch + var(--line-number-padding) * 2 + var(--line-number-right-margin)); 9ch + var(--line-number-padding) * 2 + var(--line-number-right-margin));
} }

View file

@ -60,11 +60,11 @@
removeClass(document.documentElement, "sans-serif"); removeClass(document.documentElement, "sans-serif");
} }
break; break;
case "wrap-source-code": case "word-wrap-source-code":
if (value === true) { if (value === true) {
addClass(document.documentElement, "wrap-source-code"); addClass(document.documentElement, "word-wrap-source-code");
} else { } else {
removeClass(document.documentElement, "wrap-source-code"); removeClass(document.documentElement, "word-wrap-source-code");
} }
break; break;
} }
@ -255,8 +255,8 @@
"default": false, "default": false,
}, },
{ {
"name": "Wrap source codes", "name": "Word wrap source code",
"js_name": "wrap-source-code", "js_name": "word-wrap-source-code",
"default": false, "default": false,
}, },
]; ];

View file

@ -286,8 +286,8 @@ if (getSettingValue("hide-modnav") === "true") {
if (getSettingValue("sans-serif-fonts") === "true") { if (getSettingValue("sans-serif-fonts") === "true") {
addClass(document.documentElement, "sans-serif"); addClass(document.documentElement, "sans-serif");
} }
if (getSettingValue("wrap-source-code") === "true") { if (getSettingValue("word-wrap-source-code") === "true") {
addClass(document.documentElement, "wrap-source-code"); addClass(document.documentElement, "word-wrap-source-code");
} }
function updateSidebarWidth() { function updateSidebarWidth() {
const desktopSidebarWidth = getSettingValue("desktop-sidebar-width"); const desktopSidebarWidth = getSettingValue("desktop-sidebar-width");

View file

@ -1,13 +1,14 @@
// Checks that the interactions with the source code pages are working as expected. // Checks that the interactions with the source code pages are working as expected.
go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html" go-to: "file://" + |DOC_PATH| + "/src/test_docs/lib.rs.html"
show-text: true show-text: true
set-window-size: (1000, 1000)
define-function: ( define-function: (
"click-code-wrapping", "click-code-wrapping",
[expected], [expected],
block { block {
click: "#wrap-source-code" click: "#word-wrap-source-code"
wait-for-local-storage: {"rustdoc-wrap-source-code": |expected|} wait-for-local-storage: {"rustdoc-word-wrap-source-code": |expected|}
}, },
) )
@ -15,6 +16,7 @@ store-size: (".rust code", {"width": width, "height": height})
click: "#settings-menu" click: "#settings-menu"
wait-for: "#settings" wait-for: "#settings"
call-function: ("click-code-wrapping", {"expected": "true"}) call-function: ("click-code-wrapping", {"expected": "true"})
wait-for-size-false: (".rust code", {"width": |width|, "height": |height|})
store-size: (".rust code", {"width": new_width, "height": new_height}) store-size: (".rust code", {"width": new_width, "height": new_height})
// The width should now be smaller than the window's and the height // The width should now be smaller than the window's and the height
// should have increased. // should have increased.
@ -32,6 +34,7 @@ wait-for: "#settings"
store-size: (".example-wrap .rust code", {"width": rust_width, "height": rust_height}) store-size: (".example-wrap .rust code", {"width": rust_width, "height": rust_height})
store-size: (".example-wrap .language-text code", {"width": txt_width, "height": txt_height}) store-size: (".example-wrap .language-text code", {"width": txt_width, "height": txt_height})
call-function: ("click-code-wrapping", {"expected": "true"}) call-function: ("click-code-wrapping", {"expected": "true"})
wait-for-size-false: (".example-wrap .rust code", {"width": |rust_width|, "height": |rust_height|})
store-size: (".example-wrap .rust code", {"width": new_rust_width, "height": new_rust_height}) store-size: (".example-wrap .rust code", {"width": new_rust_width, "height": new_rust_height})
store-size: (".example-wrap .language-text code", {"width": new_txt_width, "height": new_txt_height}) store-size: (".example-wrap .language-text code", {"width": new_txt_width, "height": new_txt_height})
@ -40,5 +43,5 @@ assert: |rust_width| > |new_rust_width| && |rust_height| < |new_rust_height|
assert: |txt_width| > |new_txt_width| && |txt_height| < |new_txt_height| assert: |txt_width| > |new_txt_width| && |txt_height| < |new_txt_height|
call-function: ("click-code-wrapping", {"expected": "false"}) call-function: ("click-code-wrapping", {"expected": "false"})
assert-size: (".example-wrap .rust code", {"width": |rust_width|, "height": |rust_height|}) wait-for-size: (".example-wrap .rust code", {"width": |rust_width|, "height": |rust_height|})
assert-size: (".example-wrap .language-text code", {"width": |txt_width|, "height": |txt_height|}) assert-size: (".example-wrap .language-text code", {"width": |txt_width|, "height": |txt_height|})