Skip to content

Commit 664dd95

Browse files
committed
Support maximizing editor to viewport size
Related feedback: uBlockOrigin/uBlock-issues#3161 (comment)
1 parent 710d8c6 commit 664dd95

File tree

4 files changed

+77
-31
lines changed

4 files changed

+77
-31
lines changed

src/css/codemirror.css

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
overflow: hidden;
44
position: relative;
55
}
6+
.codeMirrorContainer.cm-maximized {
7+
bottom: 0;
8+
left: 0;
9+
position: absolute;
10+
right: 0;
11+
top: 0;
12+
}
613
.CodeMirror {
714
background-color: var(--surface-0);
815
box-sizing: border-box;
@@ -176,16 +183,42 @@
176183
text-align: end;
177184
}
178185

186+
.cm-search-widget .cm-maximize {
187+
fill: none;
188+
flex-grow: 0;
189+
font-size: 140%;
190+
height: 1em;
191+
stroke-width: 3px;
192+
stroke: var(--ink-0);
193+
width: 1em;
194+
}
195+
.cm-search-widget .cm-maximize * {
196+
pointer-events: none;
197+
}
198+
.codeMirrorContainer[data-maximizable="false"] .cm-search-widget .cm-maximize {
199+
display: none;
200+
}
201+
.codeMirrorContainer .cm-search-widget .cm-maximize svg > path:nth-child(2),
202+
.codeMirrorContainer.cm-maximized .cm-search-widget .cm-maximize svg > path:nth-child(1) {
203+
display: none;
204+
}
205+
.codeMirrorContainer.cm-maximized .cm-search-widget .cm-maximize svg > path:nth-child(2) {
206+
display: initial;
207+
}
208+
html:not(.mobile) .cm-search-widget .cm-maximize:hover {
209+
transform: scale(1.2);
210+
}
211+
179212
.cm-search-widget-input {
180213
display: inline-flex;
181214
flex-grow: 1;
215+
flex-wrap: nowrap;
182216
}
183217
.cm-search-widget .fa-icon {
184-
fill: var(--cm-gutter-ink);
185218
font-size: 140%;
186219
}
187-
.cm-search-widget .fa-icon:not(.fa-icon-ro):hover {
188-
fill: var(--ink-1);
220+
html:not(.mobile) .cm-search-widget .fa-icon:not(.fa-icon-ro):hover {
221+
transform: scale(1.2);
189222
}
190223
.cm-search-widget-input input {
191224
border: 1px solid var(--cm-gutter-ink);
@@ -198,7 +231,6 @@
198231
display: inline-flex;
199232
flex-grow: 0;
200233
font-size: var(--font-size-smaller);
201-
min-width: 6em;
202234
visibility: hidden;
203235
}
204236
.cm-search-widget[data-query] .cm-search-widget-count {
@@ -207,9 +239,6 @@
207239
.cm-search-widget[data-query] .cm-search-widget-count:empty {
208240
visibility: hidden;
209241
}
210-
.cm-search-widget .cm-search-widget-button:hover {
211-
color: #000;
212-
}
213242
.cm-search-widget .sourceURL[href=""] {
214243
visibility: hidden;
215244
}

src/css/common.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ body {
5252
margin: 0;
5353
padding: 0;
5454
}
55-
a {
55+
a:not(.fa-icon) {
5656
color: var(--link-ink);
5757
fill: var(--link-ink);
5858
}
59-
a:hover {
59+
a:not(.fa-icon):hover {
6060
color: var(--link-hover-ink);
6161
fill: var(--link-hover-ink);
6262
}

src/js/asset-viewer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import './codemirror/ubo-static-filtering.js';
6060
lineWrapping: true,
6161
matchBrackets: true,
6262
maxScanLines: 1,
63+
maximizable: false,
6364
readOnly: true,
6465
styleActiveLine: {
6566
nonEmpty: true,

src/js/codemirror/search.js

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ import { i18n$ } from '../i18n.js';
3333
{
3434
const CodeMirror = self.CodeMirror;
3535

36+
CodeMirror.defineOption('maximizable', true, (cm, maximizable) => {
37+
if ( typeof maximizable !== 'boolean' ) { return; }
38+
const wrapper = cm.getWrapperElement();
39+
if ( wrapper === null ) { return; }
40+
const container = wrapper.closest('.codeMirrorContainer');
41+
if ( container === null ) { return; }
42+
container.dataset.maximizable = `${maximizable}`;
43+
});
44+
3645
const searchOverlay = function(query, caseInsensitive) {
3746
if ( typeof query === 'string' )
3847
query = new RegExp(
@@ -90,7 +99,8 @@ import { i18n$ } from '../i18n.js';
9099
};
91100

92101
const searchWidgetClickHandler = function(cm, ev) {
93-
const tcl = ev.target.classList;
102+
const target = ev.target;
103+
const tcl = target.classList;
94104
if ( tcl.contains('cm-search-widget-up') ) {
95105
findNext(cm, -1);
96106
} else if ( tcl.contains('cm-search-widget-down') ) {
@@ -99,8 +109,13 @@ import { i18n$ } from '../i18n.js';
99109
findNextError(cm, -1);
100110
} else if ( tcl.contains('cm-linter-widget-down') ) {
101111
findNextError(cm, 1);
112+
} else if ( tcl.contains('cm-maximize') ) {
113+
const container = target.closest('.codeMirrorContainer');
114+
if ( container !== null ) {
115+
container.classList.toggle('cm-maximized');
116+
}
102117
}
103-
if ( ev.target.localName !== 'input' ) {
118+
if ( target.localName !== 'input' ) {
104119
ev.preventDefault();
105120
} else {
106121
ev.stopImmediatePropagation();
@@ -458,26 +473,27 @@ import { i18n$ } from '../i18n.js';
458473
};
459474

460475
{
461-
const searchWidgetTemplate =
462-
'<div class="cm-search-widget-template" style="display:none;">' +
463-
'<div class="cm-search-widget">' +
464-
'<span class="cm-search-widget-input">' +
465-
'<span class="fa-icon fa-icon-ro">search</span>&ensp;' +
466-
'<input type="search" spellcheck="false">&emsp;' +
467-
'<span class="cm-search-widget-up cm-search-widget-button fa-icon">angle-up</span>&nbsp;' +
468-
'<span class="cm-search-widget-down cm-search-widget-button fa-icon fa-icon-vflipped">angle-up</span>&emsp;' +
469-
'<span class="cm-search-widget-count"></span>' +
470-
'</span>' +
471-
'<span class="cm-linter-widget" data-lint="0">' +
472-
'<span class="cm-linter-widget-count"></span>&emsp;' +
473-
'<span class="cm-linter-widget-up cm-search-widget-button fa-icon">angle-up</span>&nbsp;' +
474-
'<span class="cm-linter-widget-down cm-search-widget-button fa-icon fa-icon-vflipped">angle-up</span>&emsp;' +
475-
'</span>' +
476-
'<span>' +
477-
'<a class="fa-icon sourceURL" href>external-link</a>' +
478-
'</span>' +
479-
'</div>' +
480-
'</div>';
476+
const searchWidgetTemplate = [
477+
'<div class="cm-search-widget-template" style="display:none;">',
478+
'<div class="cm-search-widget">',
479+
'<span class="cm-maximize"><svg viewBox="0 0 40 40"><path d="M4,16V4h12M24,4H36V16M4,24V36H16M36,24V36H24" /><path d="M14 2.5v12h-12M38 14h-12v-12M14 38v-12h-12M26 38v-12h12" /></svg></span>&ensp;',
480+
'<span class="cm-search-widget-input">',
481+
'<input type="search" spellcheck="false" placeholder="&#x26B2;">&ensp;',
482+
'<span class="cm-search-widget-up cm-search-widget-button fa-icon">angle-up</span>&nbsp;',
483+
'<span class="cm-search-widget-down cm-search-widget-button fa-icon fa-icon-vflipped">angle-up</span>&ensp;',
484+
'<span class="cm-search-widget-count"></span>',
485+
'</span>',
486+
'<span class="cm-linter-widget" data-lint="0">',
487+
'<span class="cm-linter-widget-count"></span>&ensp;',
488+
'<span class="cm-linter-widget-up cm-search-widget-button fa-icon">angle-up</span>&nbsp;',
489+
'<span class="cm-linter-widget-down cm-search-widget-button fa-icon fa-icon-vflipped">angle-up</span>&ensp;',
490+
'</span>',
491+
'<span>',
492+
'<a class="fa-icon sourceURL" href>external-link</a>',
493+
'</span>',
494+
'</div>',
495+
'</div>',
496+
].join('\n');
481497
const domParser = new DOMParser();
482498
const doc = domParser.parseFromString(searchWidgetTemplate, 'text/html');
483499
const widgetTemplate = document.adoptNode(doc.body.firstElementChild);

0 commit comments

Comments
 (0)