mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-25 01:06:16 -04:00
Automatically detect EOL from paste events and output setting
This commit is contained in:
parent
c4e7c41a6e
commit
16dfb3fac6
7 changed files with 215 additions and 43 deletions
|
@ -6,6 +6,7 @@
|
|||
|
||||
import {showPanel} from "@codemirror/view";
|
||||
import {CHR_ENC_SIMPLE_LOOKUP, CHR_ENC_SIMPLE_REVERSE_LOOKUP} from "../../core/lib/ChrEnc.mjs";
|
||||
import { eolCodeToName, eolSeqToCode } from "./editorUtils.mjs";
|
||||
|
||||
/**
|
||||
* A Status bar extension for CodeMirror
|
||||
|
@ -92,22 +93,12 @@ class StatusBarPanel {
|
|||
// preventDefault is required to stop the URL being modified and popState being triggered
|
||||
e.preventDefault();
|
||||
|
||||
const eolLookup = {
|
||||
"LF": "\u000a",
|
||||
"VT": "\u000b",
|
||||
"FF": "\u000c",
|
||||
"CR": "\u000d",
|
||||
"CRLF": "\u000d\u000a",
|
||||
"NEL": "\u0085",
|
||||
"LS": "\u2028",
|
||||
"PS": "\u2029"
|
||||
};
|
||||
const eolval = eolLookup[e.target.getAttribute("data-val")];
|
||||
|
||||
if (eolval === undefined) return;
|
||||
const eolCode = e.target.getAttribute("data-val");
|
||||
if (!eolCode) return;
|
||||
|
||||
// Call relevant EOL change handler
|
||||
this.eolHandler(eolval);
|
||||
this.eolHandler(e.target.getAttribute("data-val"), true);
|
||||
|
||||
hideElement(e.target.closest(".cm-status-bar-select-content"));
|
||||
}
|
||||
|
||||
|
@ -223,23 +214,13 @@ class StatusBarPanel {
|
|||
updateEOL(state) {
|
||||
if (state.lineBreak === this.eolVal) return;
|
||||
|
||||
const eolLookup = {
|
||||
"\u000a": ["LF", "Line Feed"],
|
||||
"\u000b": ["VT", "Vertical Tab"],
|
||||
"\u000c": ["FF", "Form Feed"],
|
||||
"\u000d": ["CR", "Carriage Return"],
|
||||
"\u000d\u000a": ["CRLF", "Carriage Return + Line Feed"],
|
||||
"\u0085": ["NEL", "Next Line"],
|
||||
"\u2028": ["LS", "Line Separator"],
|
||||
"\u2029": ["PS", "Paragraph Separator"]
|
||||
};
|
||||
|
||||
const val = this.dom.querySelector(".eol-value");
|
||||
const button = val.closest(".cm-status-bar-select-btn");
|
||||
const eolName = eolLookup[state.lineBreak];
|
||||
val.textContent = eolName[0];
|
||||
button.setAttribute("title", `End of line sequence:<br>${eolName[1]}`);
|
||||
button.setAttribute("data-original-title", `End of line sequence:<br>${eolName[1]}`);
|
||||
const eolCode = eolSeqToCode[state.lineBreak];
|
||||
const eolName = eolCodeToName[eolCode];
|
||||
val.textContent = eolCode;
|
||||
button.setAttribute("title", `End of line sequence:<br>${eolName}`);
|
||||
button.setAttribute("data-original-title", `End of line sequence:<br>${eolName}`);
|
||||
this.eolVal = state.lineBreak;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue