MCPcopy Index your code
hub / github.com/zxlie/FeHelper / _bindPrettyJsonShortcuts

Function _bindPrettyJsonShortcuts

apps/json-format/format-lib.js:209–258  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

207 };
208
209 let _bindPrettyJsonShortcuts = function () {
210 if (prettyJsonShortcutBound || !document.addEventListener) return;
211 prettyJsonShortcutBound = true;
212 document.addEventListener('keydown', function (event) {
213 let key = String(event.key || '').toLowerCase();
214 if (key === 'escape' && (plainJsonViewEnabled || prettyJsonSelectionActive) && _hasPrettyJsonResult()) {
215 event.preventDefault();
216 event.stopPropagation();
217 _exitPrettyJsonSelection();
218 return;
219 }
220
221 let isShortcut = event.ctrlKey || event.metaKey;
222 if (!isShortcut || event.altKey || event.shiftKey) return;
223
224 if (key === 'a') {
225 if (_isEditableShortcutTarget(event.target) || !_hasPrettyJsonResult()) {
226 prettyJsonSelectionActive = false;
227 return;
228 }
229 if (_selectPrettyJsonText()) {
230 event.preventDefault();
231 event.stopPropagation();
232 }
233 return;
234 }
235
236 if (key === 'c') {
237 if (prettyJsonSelectionActive && _hasPrettyJsonResult()) {
238 event.preventDefault();
239 event.stopPropagation();
240 prettyJsonSelectionActive = false;
241 _copyToClipboard(cachedJsonString, '格式化后的 JSON 全文已复制到剪贴板!');
242 return;
243 }
244 if (_isEditableShortcutTarget(event.target)) {
245 prettyJsonSelectionActive = false;
246 }
247 return;
248 }
249
250 prettyJsonSelectionActive = false;
251 }, true);
252 document.addEventListener('copy', function (event) {
253 _copyPrettyJsonSelection(event);
254 }, true);
255 document.addEventListener('mousedown', function () {
256 prettyJsonSelectionActive = false;
257 }, true);
258 };
259
260 let _initElements = function () {
261

Callers 1

_initElementsFunction · 0.85

Calls 7

_hasPrettyJsonResultFunction · 0.85
_exitPrettyJsonSelectionFunction · 0.85
_selectPrettyJsonTextFunction · 0.85
_copyPrettyJsonSelectionFunction · 0.85
_copyToClipboardFunction · 0.70
addEventListenerMethod · 0.45

Tested by

no test coverage detected