-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresize-quickinput-widget.js
197 lines (185 loc) · 6.44 KB
/
resize-quickinput-widget.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
* GNU GENERAL PUBLIC LICENSE
* Version 3, 29 June 2007
*
* Copyright (C) [2023] [Captain Vincent]
* Original Source: https://gist.github.com/CaptainVincent/74a15cd9d9c450e961b867f69008ee6e
*
* Everyone is permitted to copy and distribute verbatim copies of this license document,
* but changing it is not allowed.
*
* Preamble
*
* The GNU General Public License is a free, copyleft license for software and other kinds of works.
*
* The licenses for most software and other practical works are designed to take away your freedom
* to share and change the works. By contrast, the GNU General Public License is intended to guarantee
* your freedom to share and change all versions of a program—to make sure it remains free software
* for all its users.
*
* resize-quickinput-widget.js
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not, see
* https://www.gnu.org/licenses/.
*/
var menuExist = false;
var quickInputListNode = null;
var factor = 1;
var refresh = false;
var cachedHeight = -1;
var cachedPreOneTop = 0;
const padding = 10; // up + bottom
// Init static style
var styleElement = document.createElement("style");
var styles = `
.quick-input-widget {
transform: translateY(-50%) !important;
top: 47% !important;
box-shadow: 0 0 60px 0 rgba(0,0,0,0.2) !important;
width: 700px !important;
left: calc(50% - 50px) !important;
}
.quick-input-widget .monaco-inputbox {
padding: 10px 10px 10px 10px !important;
border-top-left-radius:5px!important;
border-top-right-radius:5px!important;
border-top: 0!important;
border-left: 0!important;
border-right: 0!important;
}
.quick-input-widget .quick-input-action {
padding-top: 10px !important;
font-size: 14px !important;
}i
.quick-input-widget .monaco-list-rows {
font-size: 13px !important;
}
.quick-input-widget .monaco-list-row {
padding: 10px !important;
height: auto !important;
}
.quick-input-widget .quick-input-list-entry {
position: relative;
padding: 0px 0px 0px 0px;
}
.quick-input-widget .quick-input-list-entry .codicon[class*=codicon-] {
font-size: 16px;
}
.quick-input-widget .quick-input-list .quick-input-list-entry.quick-input-list-separator-border {
border-top-width: 0px !important;
}
.quick-input-widget .quick-input-list .quick-input-list-label-meta .monaco-highlighted-label:before {
content: ' ▸ ';
}
.quick-input-widget .quick-input-list .quick-input-list-entry .monaco-action-bar.animated.quick-input-list-entry-action-bar {
height: unset;
}
.editor-group-watermark {
max-width: 500px !important;
padding-left: 1em;
padding-right: 1em;
}
}
`;
styleElement.textContent = styles;
document.head.appendChild(styleElement);
function zoom(obj, primaryKey, cacheKey) {
const v = parseInt(obj.style[primaryKey], 10);
if (refresh || !obj.hasOwnProperty(cacheKey) || obj[cacheKey] != v) {
set(obj, Math.round(v * factor), primaryKey, cacheKey);
return true;
}
return v === 0;
}
function set(obj, v, primaryKey, cacheKey) {
obj[cacheKey] = v;
obj.style[primaryKey] = obj[cacheKey] + "px";
}
function setPaddingBottom(obj, v) {
if (parseInt(obj.style.paddingBottom, 10) != v) {
obj.style["paddingBottom"] = v + "px";
}
}
function resize() {
const monacoListRows =
quickInputListNode.querySelector(".monaco-list-rows");
const rows = quickInputListNode.querySelectorAll(
".monaco-list-rows .monaco-list-row"
);
refresh = false;
if (rows && rows.length > 0) {
var defaultHeight = parseInt(rows[0].style.height, 10);
if (defaultHeight != cachedHeight) {
factor = (defaultHeight + 10) / defaultHeight;
cachedHeight = defaultHeight;
refresh = true;
}
cachedPreOneTop = parseInt(rows[0].style.top, 10);
setPaddingBottom(quickInputListNode, 5);
} else {
setPaddingBottom(quickInputListNode, 0);
return;
}
zoom(quickInputListNode, "maxHeight", "cachedMaxHeight");
zoom(monacoListRows, "height", "cachedHeight");
zoom(monacoListRows, "top", "cachedTop");
moving = false;
rows.forEach((row) => {
moving = zoom(row, "top", "cachedTop") || moving;
// [[Patch]]
// Fix a bug that some rows are not moving, so
// I force-set their top based on the previous one.
if (moving && parseInt(row.style.top, 10) < cachedPreOneTop) {
set(
row,
cachedPreOneTop +
Math.floor(parseInt(row.style.height, 10) * factor),
"top",
"cachedTop"
);
}
cachedPreOneTop = parseInt(row.style.top, 10);
});
const scrollbar = quickInputListNode.querySelector(".scrollbar.vertical");
if (scrollbar) {
zoom(scrollbar, "height", "cachedHeight");
slider = scrollbar.querySelector(".slider");
zoom(slider, "height", "cachedHeight");
zoom(slider, "top", "cachedTop");
}
}
const target = document.body;
const config = { attributes: true, childList: true, subtree: true };
const observer = new MutationObserver((mutationsList) => {
for (let mutation of mutationsList) {
if (
!menuExist &&
mutation.type === "childList" &&
mutation.addedNodes.length > 0
) {
quickInputListNode = document.getElementById("quickInput_list");
if (quickInputListNode) {
menuExist = true;
resize();
const maxHeightObserver = new MutationObserver(
mutationsList => resize()
);
maxHeightObserver.observe(quickInputListNode, {
attributes: true,
childList: true,
subtree: true,
attributeFilter: ["style"],
});
}
}
}
});
observer.observe(target, config);