| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542 |
- import { Annotation, Facet, combineConfig, StateField, EditorSelection, Transaction, ChangeSet, ChangeDesc, StateEffect, Text, findClusterBreak, countColumn, CharCategory } from '@codemirror/state';
- import { EditorView, Direction } from '@codemirror/view';
- import { IndentContext, getIndentation, indentString, indentUnit, getIndentUnit, matchBrackets, syntaxTree } from '@codemirror/language';
- import { NodeProp } from '@lezer/common';
- /**
- Comment or uncomment the current selection. Will use line comments
- if available, otherwise falling back to block comments.
- */
- const toggleComment = target => {
- let config = getConfig(target.state);
- return config.line ? toggleLineComment(target) : config.block ? toggleBlockCommentByLine(target) : false;
- };
- function command(f, option) {
- return ({ state, dispatch }) => {
- if (state.readOnly)
- return false;
- let tr = f(option, state);
- if (!tr)
- return false;
- dispatch(state.update(tr));
- return true;
- };
- }
- /**
- Comment or uncomment the current selection using line comments.
- The line comment syntax is taken from the
- [`commentTokens`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) [language
- data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt).
- */
- const toggleLineComment = /*@__PURE__*/command(changeLineComment, 0 /* Toggle */);
- /**
- Comment the current selection using line comments.
- */
- const lineComment = /*@__PURE__*/command(changeLineComment, 1 /* Comment */);
- /**
- Uncomment the current selection using line comments.
- */
- const lineUncomment = /*@__PURE__*/command(changeLineComment, 2 /* Uncomment */);
- /**
- Comment or uncomment the current selection using block comments.
- The block comment syntax is taken from the
- [`commentTokens`](https://codemirror.net/6/docs/ref/#commands.CommentTokens) [language
- data](https://codemirror.net/6/docs/ref/#state.EditorState.languageDataAt).
- */
- const toggleBlockComment = /*@__PURE__*/command(changeBlockComment, 0 /* Toggle */);
- /**
- Comment the current selection using block comments.
- */
- const blockComment = /*@__PURE__*/command(changeBlockComment, 1 /* Comment */);
- /**
- Uncomment the current selection using block comments.
- */
- const blockUncomment = /*@__PURE__*/command(changeBlockComment, 2 /* Uncomment */);
- /**
- Comment or uncomment the lines around the current selection using
- block comments.
- */
- const toggleBlockCommentByLine = /*@__PURE__*/command((o, s) => changeBlockComment(o, s, selectedLineRanges(s)), 0 /* Toggle */);
- function getConfig(state, pos = state.selection.main.head) {
- let data = state.languageDataAt("commentTokens", pos);
- return data.length ? data[0] : {};
- }
- const SearchMargin = 50;
- /**
- Determines if the given range is block-commented in the given
- state.
- */
- function findBlockComment(state, { open, close }, from, to) {
- let textBefore = state.sliceDoc(from - SearchMargin, from);
- let textAfter = state.sliceDoc(to, to + SearchMargin);
- let spaceBefore = /\s*$/.exec(textBefore)[0].length, spaceAfter = /^\s*/.exec(textAfter)[0].length;
- let beforeOff = textBefore.length - spaceBefore;
- if (textBefore.slice(beforeOff - open.length, beforeOff) == open &&
- textAfter.slice(spaceAfter, spaceAfter + close.length) == close) {
- return { open: { pos: from - spaceBefore, margin: spaceBefore && 1 },
- close: { pos: to + spaceAfter, margin: spaceAfter && 1 } };
- }
- let startText, endText;
- if (to - from <= 2 * SearchMargin) {
- startText = endText = state.sliceDoc(from, to);
- }
- else {
- startText = state.sliceDoc(from, from + SearchMargin);
- endText = state.sliceDoc(to - SearchMargin, to);
- }
- let startSpace = /^\s*/.exec(startText)[0].length, endSpace = /\s*$/.exec(endText)[0].length;
- let endOff = endText.length - endSpace - close.length;
- if (startText.slice(startSpace, startSpace + open.length) == open &&
- endText.slice(endOff, endOff + close.length) == close) {
- return { open: { pos: from + startSpace + open.length,
- margin: /\s/.test(startText.charAt(startSpace + open.length)) ? 1 : 0 },
- close: { pos: to - endSpace - close.length,
- margin: /\s/.test(endText.charAt(endOff - 1)) ? 1 : 0 } };
- }
- return null;
- }
- function selectedLineRanges(state) {
- let ranges = [];
- for (let r of state.selection.ranges) {
- let fromLine = state.doc.lineAt(r.from);
- let toLine = r.to <= fromLine.to ? fromLine : state.doc.lineAt(r.to);
- let last = ranges.length - 1;
- if (last >= 0 && ranges[last].to > fromLine.from)
- ranges[last].to = toLine.to;
- else
- ranges.push({ from: fromLine.from, to: toLine.to });
- }
- return ranges;
- }
- // Performs toggle, comment and uncomment of block comments in
- // languages that support them.
- function changeBlockComment(option, state, ranges = state.selection.ranges) {
- let tokens = ranges.map(r => getConfig(state, r.from).block);
- if (!tokens.every(c => c))
- return null;
- let comments = ranges.map((r, i) => findBlockComment(state, tokens[i], r.from, r.to));
- if (option != 2 /* Uncomment */ && !comments.every(c => c)) {
- return { changes: state.changes(ranges.map((range, i) => {
- if (comments[i])
- return [];
- return [{ from: range.from, insert: tokens[i].open + " " }, { from: range.to, insert: " " + tokens[i].close }];
- })) };
- }
- else if (option != 1 /* Comment */ && comments.some(c => c)) {
- let changes = [];
- for (let i = 0, comment; i < comments.length; i++)
- if (comment = comments[i]) {
- let token = tokens[i], { open, close } = comment;
- changes.push({ from: open.pos - token.open.length, to: open.pos + open.margin }, { from: close.pos - close.margin, to: close.pos + token.close.length });
- }
- return { changes };
- }
- return null;
- }
- // Performs toggle, comment and uncomment of line comments.
- function changeLineComment(option, state, ranges = state.selection.ranges) {
- let lines = [];
- let prevLine = -1;
- for (let { from, to } of ranges) {
- let startI = lines.length, minIndent = 1e9;
- for (let pos = from; pos <= to;) {
- let line = state.doc.lineAt(pos);
- if (line.from > prevLine && (from == to || to > line.from)) {
- prevLine = line.from;
- let token = getConfig(state, pos).line;
- if (!token)
- continue;
- let indent = /^\s*/.exec(line.text)[0].length;
- let empty = indent == line.length;
- let comment = line.text.slice(indent, indent + token.length) == token ? indent : -1;
- if (indent < line.text.length && indent < minIndent)
- minIndent = indent;
- lines.push({ line, comment, token, indent, empty, single: false });
- }
- pos = line.to + 1;
- }
- if (minIndent < 1e9)
- for (let i = startI; i < lines.length; i++)
- if (lines[i].indent < lines[i].line.text.length)
- lines[i].indent = minIndent;
- if (lines.length == startI + 1)
- lines[startI].single = true;
- }
- if (option != 2 /* Uncomment */ && lines.some(l => l.comment < 0 && (!l.empty || l.single))) {
- let changes = [];
- for (let { line, token, indent, empty, single } of lines)
- if (single || !empty)
- changes.push({ from: line.from + indent, insert: token + " " });
- let changeSet = state.changes(changes);
- return { changes: changeSet, selection: state.selection.map(changeSet, 1) };
- }
- else if (option != 1 /* Comment */ && lines.some(l => l.comment >= 0)) {
- let changes = [];
- for (let { line, comment, token } of lines)
- if (comment >= 0) {
- let from = line.from + comment, to = from + token.length;
- if (line.text[to - line.from] == " ")
- to++;
- changes.push({ from, to });
- }
- return { changes };
- }
- return null;
- }
- const fromHistory = /*@__PURE__*/Annotation.define();
- /**
- Transaction annotation that will prevent that transaction from
- being combined with other transactions in the undo history. Given
- `"before"`, it'll prevent merging with previous transactions. With
- `"after"`, subsequent transactions won't be combined with this
- one. With `"full"`, the transaction is isolated on both sides.
- */
- const isolateHistory = /*@__PURE__*/Annotation.define();
- /**
- This facet provides a way to register functions that, given a
- transaction, provide a set of effects that the history should
- store when inverting the transaction. This can be used to
- integrate some kinds of effects in the history, so that they can
- be undone (and redone again).
- */
- const invertedEffects = /*@__PURE__*/Facet.define();
- const historyConfig = /*@__PURE__*/Facet.define({
- combine(configs) {
- return combineConfig(configs, {
- minDepth: 100,
- newGroupDelay: 500
- }, { minDepth: Math.max, newGroupDelay: Math.min });
- }
- });
- function changeEnd(changes) {
- let end = 0;
- changes.iterChangedRanges((_, to) => end = to);
- return end;
- }
- const historyField_ = /*@__PURE__*/StateField.define({
- create() {
- return HistoryState.empty;
- },
- update(state, tr) {
- let config = tr.state.facet(historyConfig);
- let fromHist = tr.annotation(fromHistory);
- if (fromHist) {
- let selection = tr.docChanged ? EditorSelection.single(changeEnd(tr.changes)) : undefined;
- let item = HistEvent.fromTransaction(tr, selection), from = fromHist.side;
- let other = from == 0 /* Done */ ? state.undone : state.done;
- if (item)
- other = updateBranch(other, other.length, config.minDepth, item);
- else
- other = addSelection(other, tr.startState.selection);
- return new HistoryState(from == 0 /* Done */ ? fromHist.rest : other, from == 0 /* Done */ ? other : fromHist.rest);
- }
- let isolate = tr.annotation(isolateHistory);
- if (isolate == "full" || isolate == "before")
- state = state.isolate();
- if (tr.annotation(Transaction.addToHistory) === false)
- return !tr.changes.empty ? state.addMapping(tr.changes.desc) : state;
- let event = HistEvent.fromTransaction(tr);
- let time = tr.annotation(Transaction.time), userEvent = tr.annotation(Transaction.userEvent);
- if (event)
- state = state.addChanges(event, time, userEvent, config.newGroupDelay, config.minDepth);
- else if (tr.selection)
- state = state.addSelection(tr.startState.selection, time, userEvent, config.newGroupDelay);
- if (isolate == "full" || isolate == "after")
- state = state.isolate();
- return state;
- },
- toJSON(value) {
- return { done: value.done.map(e => e.toJSON()), undone: value.undone.map(e => e.toJSON()) };
- },
- fromJSON(json) {
- return new HistoryState(json.done.map(HistEvent.fromJSON), json.undone.map(HistEvent.fromJSON));
- }
- });
- /**
- Create a history extension with the given configuration.
- */
- function history(config = {}) {
- return [
- historyField_,
- historyConfig.of(config),
- EditorView.domEventHandlers({
- beforeinput(e, view) {
- let command = e.inputType == "historyUndo" ? undo : e.inputType == "historyRedo" ? redo : null;
- if (!command)
- return false;
- e.preventDefault();
- return command(view);
- }
- })
- ];
- }
- /**
- The state field used to store the history data. Should probably
- only be used when you want to
- [serialize](https://codemirror.net/6/docs/ref/#state.EditorState.toJSON) or
- [deserialize](https://codemirror.net/6/docs/ref/#state.EditorState^fromJSON) state objects in a way
- that preserves history.
- */
- const historyField = historyField_;
- function cmd(side, selection) {
- return function ({ state, dispatch }) {
- if (!selection && state.readOnly)
- return false;
- let historyState = state.field(historyField_, false);
- if (!historyState)
- return false;
- let tr = historyState.pop(side, state, selection);
- if (!tr)
- return false;
- dispatch(tr);
- return true;
- };
- }
- /**
- Undo a single group of history events. Returns false if no group
- was available.
- */
- const undo = /*@__PURE__*/cmd(0 /* Done */, false);
- /**
- Redo a group of history events. Returns false if no group was
- available.
- */
- const redo = /*@__PURE__*/cmd(1 /* Undone */, false);
- /**
- Undo a change or selection change.
- */
- const undoSelection = /*@__PURE__*/cmd(0 /* Done */, true);
- /**
- Redo a change or selection change.
- */
- const redoSelection = /*@__PURE__*/cmd(1 /* Undone */, true);
- function depth(side) {
- return function (state) {
- let histState = state.field(historyField_, false);
- if (!histState)
- return 0;
- let branch = side == 0 /* Done */ ? histState.done : histState.undone;
- return branch.length - (branch.length && !branch[0].changes ? 1 : 0);
- };
- }
- /**
- The amount of undoable change events available in a given state.
- */
- const undoDepth = /*@__PURE__*/depth(0 /* Done */);
- /**
- The amount of redoable change events available in a given state.
- */
- const redoDepth = /*@__PURE__*/depth(1 /* Undone */);
- // History events store groups of changes or effects that need to be
- // undone/redone together.
- class HistEvent {
- constructor(
- // The changes in this event. Normal events hold at least one
- // change or effect. But it may be necessary to store selection
- // events before the first change, in which case a special type of
- // instance is created which doesn't hold any changes, with
- // changes == startSelection == undefined
- changes,
- // The effects associated with this event
- effects,
- // Accumulated mapping (from addToHistory==false) that should be
- // applied to events below this one.
- mapped,
- // The selection before this event
- startSelection,
- // Stores selection changes after this event, to be used for
- // selection undo/redo.
- selectionsAfter) {
- this.changes = changes;
- this.effects = effects;
- this.mapped = mapped;
- this.startSelection = startSelection;
- this.selectionsAfter = selectionsAfter;
- }
- setSelAfter(after) {
- return new HistEvent(this.changes, this.effects, this.mapped, this.startSelection, after);
- }
- toJSON() {
- var _a, _b, _c;
- return {
- changes: (_a = this.changes) === null || _a === void 0 ? void 0 : _a.toJSON(),
- mapped: (_b = this.mapped) === null || _b === void 0 ? void 0 : _b.toJSON(),
- startSelection: (_c = this.startSelection) === null || _c === void 0 ? void 0 : _c.toJSON(),
- selectionsAfter: this.selectionsAfter.map(s => s.toJSON())
- };
- }
- static fromJSON(json) {
- return new HistEvent(json.changes && ChangeSet.fromJSON(json.changes), [], json.mapped && ChangeDesc.fromJSON(json.mapped), json.startSelection && EditorSelection.fromJSON(json.startSelection), json.selectionsAfter.map(EditorSelection.fromJSON));
- }
- // This does not check `addToHistory` and such, it assumes the
- // transaction needs to be converted to an item. Returns null when
- // there are no changes or effects in the transaction.
- static fromTransaction(tr, selection) {
- let effects = none;
- for (let invert of tr.startState.facet(invertedEffects)) {
- let result = invert(tr);
- if (result.length)
- effects = effects.concat(result);
- }
- if (!effects.length && tr.changes.empty)
- return null;
- return new HistEvent(tr.changes.invert(tr.startState.doc), effects, undefined, selection || tr.startState.selection, none);
- }
- static selection(selections) {
- return new HistEvent(undefined, none, undefined, undefined, selections);
- }
- }
- function updateBranch(branch, to, maxLen, newEvent) {
- let start = to + 1 > maxLen + 20 ? to - maxLen - 1 : 0;
- let newBranch = branch.slice(start, to);
- newBranch.push(newEvent);
- return newBranch;
- }
- function isAdjacent(a, b) {
- let ranges = [], isAdjacent = false;
- a.iterChangedRanges((f, t) => ranges.push(f, t));
- b.iterChangedRanges((_f, _t, f, t) => {
- for (let i = 0; i < ranges.length;) {
- let from = ranges[i++], to = ranges[i++];
- if (t >= from && f <= to)
- isAdjacent = true;
- }
- });
- return isAdjacent;
- }
- function eqSelectionShape(a, b) {
- return a.ranges.length == b.ranges.length &&
- a.ranges.filter((r, i) => r.empty != b.ranges[i].empty).length === 0;
- }
- function conc(a, b) {
- return !a.length ? b : !b.length ? a : a.concat(b);
- }
- const none = [];
- const MaxSelectionsPerEvent = 200;
- function addSelection(branch, selection) {
- if (!branch.length) {
- return [HistEvent.selection([selection])];
- }
- else {
- let lastEvent = branch[branch.length - 1];
- let sels = lastEvent.selectionsAfter.slice(Math.max(0, lastEvent.selectionsAfter.length - MaxSelectionsPerEvent));
- if (sels.length && sels[sels.length - 1].eq(selection))
- return branch;
- sels.push(selection);
- return updateBranch(branch, branch.length - 1, 1e9, lastEvent.setSelAfter(sels));
- }
- }
- // Assumes the top item has one or more selectionAfter values
- function popSelection(branch) {
- let last = branch[branch.length - 1];
- let newBranch = branch.slice();
- newBranch[branch.length - 1] = last.setSelAfter(last.selectionsAfter.slice(0, last.selectionsAfter.length - 1));
- return newBranch;
- }
- // Add a mapping to the top event in the given branch. If this maps
- // away all the changes and effects in that item, drop it and
- // propagate the mapping to the next item.
- function addMappingToBranch(branch, mapping) {
- if (!branch.length)
- return branch;
- let length = branch.length, selections = none;
- while (length) {
- let event = mapEvent(branch[length - 1], mapping, selections);
- if (event.changes && !event.changes.empty || event.effects.length) { // Event survived mapping
- let result = branch.slice(0, length);
- result[length - 1] = event;
- return result;
- }
- else { // Drop this event, since there's no changes or effects left
- mapping = event.mapped;
- length--;
- selections = event.selectionsAfter;
- }
- }
- return selections.length ? [HistEvent.selection(selections)] : none;
- }
- function mapEvent(event, mapping, extraSelections) {
- let selections = conc(event.selectionsAfter.length ? event.selectionsAfter.map(s => s.map(mapping)) : none, extraSelections);
- // Change-less events don't store mappings (they are always the last event in a branch)
- if (!event.changes)
- return HistEvent.selection(selections);
- let mappedChanges = event.changes.map(mapping), before = mapping.mapDesc(event.changes, true);
- let fullMapping = event.mapped ? event.mapped.composeDesc(before) : before;
- return new HistEvent(mappedChanges, StateEffect.mapEffects(event.effects, mapping), fullMapping, event.startSelection.map(before), selections);
- }
- const joinableUserEvent = /^(input\.type|delete)($|\.)/;
- class HistoryState {
- constructor(done, undone, prevTime = 0, prevUserEvent = undefined) {
- this.done = done;
- this.undone = undone;
- this.prevTime = prevTime;
- this.prevUserEvent = prevUserEvent;
- }
- isolate() {
- return this.prevTime ? new HistoryState(this.done, this.undone) : this;
- }
- addChanges(event, time, userEvent, newGroupDelay, maxLen) {
- let done = this.done, lastEvent = done[done.length - 1];
- if (lastEvent && lastEvent.changes && !lastEvent.changes.empty && event.changes &&
- (!userEvent || joinableUserEvent.test(userEvent)) &&
- ((!lastEvent.selectionsAfter.length &&
- time - this.prevTime < newGroupDelay &&
- isAdjacent(lastEvent.changes, event.changes)) ||
- // For compose (but not compose.start) events, always join with previous event
- userEvent == "input.type.compose")) {
- done = updateBranch(done, done.length - 1, maxLen, new HistEvent(event.changes.compose(lastEvent.changes), conc(event.effects, lastEvent.effects), lastEvent.mapped, lastEvent.startSelection, none));
- }
- else {
- done = updateBranch(done, done.length, maxLen, event);
- }
- return new HistoryState(done, none, time, userEvent);
- }
- addSelection(selection, time, userEvent, newGroupDelay) {
- let last = this.done.length ? this.done[this.done.length - 1].selectionsAfter : none;
- if (last.length > 0 &&
- time - this.prevTime < newGroupDelay &&
- userEvent == this.prevUserEvent && userEvent && /^select($|\.)/.test(userEvent) &&
- eqSelectionShape(last[last.length - 1], selection))
- return this;
- return new HistoryState(addSelection(this.done, selection), this.undone, time, userEvent);
- }
- addMapping(mapping) {
- return new HistoryState(addMappingToBranch(this.done, mapping), addMappingToBranch(this.undone, mapping), this.prevTime, this.prevUserEvent);
- }
- pop(side, state, selection) {
- let branch = side == 0 /* Done */ ? this.done : this.undone;
- if (branch.length == 0)
- return null;
- let event = branch[branch.length - 1];
- if (selection && event.selectionsAfter.length) {
- return state.update({
- selection: event.selectionsAfter[event.selectionsAfter.length - 1],
- annotations: fromHistory.of({ side, rest: popSelection(branch) }),
- userEvent: side == 0 /* Done */ ? "select.undo" : "select.redo",
- scrollIntoView: true
- });
- }
- else if (!event.changes) {
- return null;
- }
- else {
- let rest = branch.length == 1 ? none : branch.slice(0, branch.length - 1);
- if (event.mapped)
- rest = addMappingToBranch(rest, event.mapped);
- return state.update({
- changes: event.changes,
- selection: event.startSelection,
- effects: event.effects,
- annotations: fromHistory.of({ side, rest }),
- filter: false,
- userEvent: side == 0 /* Done */ ? "undo" : "redo",
- scrollIntoView: true
- });
- }
- }
- }
- HistoryState.empty = /*@__PURE__*/new HistoryState(none, none);
- /**
- Default key bindings for the undo history.
- - Mod-z: [`undo`](https://codemirror.net/6/docs/ref/#commands.undo).
- - Mod-y (Mod-Shift-z on macOS) + Ctrl-Shift-z on Linux: [`redo`](https://codemirror.net/6/docs/ref/#commands.redo).
- - Mod-u: [`undoSelection`](https://codemirror.net/6/docs/ref/#commands.undoSelection).
- - Alt-u (Mod-Shift-u on macOS): [`redoSelection`](https://codemirror.net/6/docs/ref/#commands.redoSelection).
- */
- const historyKeymap = [
- { key: "Mod-z", run: undo, preventDefault: true },
- { key: "Mod-y", mac: "Mod-Shift-z", run: redo, preventDefault: true },
- { linux: "Ctrl-Shift-z", run: redo, preventDefault: true },
- { key: "Mod-u", run: undoSelection, preventDefault: true },
- { key: "Alt-u", mac: "Mod-Shift-u", run: redoSelection, preventDefault: true }
- ];
- function updateSel(sel, by) {
- return EditorSelection.create(sel.ranges.map(by), sel.mainIndex);
- }
- function setSel(state, selection) {
- return state.update({ selection, scrollIntoView: true, userEvent: "select" });
- }
- function moveSel({ state, dispatch }, how) {
- let selection = updateSel(state.selection, how);
- if (selection.eq(state.selection))
- return false;
- dispatch(setSel(state, selection));
- return true;
- }
- function rangeEnd(range, forward) {
- return EditorSelection.cursor(forward ? range.to : range.from);
- }
- function cursorByChar(view, forward) {
- return moveSel(view, range => range.empty ? view.moveByChar(range, forward) : rangeEnd(range, forward));
- }
- function ltrAtCursor(view) {
- return view.textDirectionAt(view.state.selection.main.head) == Direction.LTR;
- }
- /**
- Move the selection one character to the left (which is backward in
- left-to-right text, forward in right-to-left text).
- */
- const cursorCharLeft = view => cursorByChar(view, !ltrAtCursor(view));
- /**
- Move the selection one character to the right.
- */
- const cursorCharRight = view => cursorByChar(view, ltrAtCursor(view));
- /**
- Move the selection one character forward.
- */
- const cursorCharForward = view => cursorByChar(view, true);
- /**
- Move the selection one character backward.
- */
- const cursorCharBackward = view => cursorByChar(view, false);
- function cursorByGroup(view, forward) {
- return moveSel(view, range => range.empty ? view.moveByGroup(range, forward) : rangeEnd(range, forward));
- }
- /**
- Move the selection to the left across one group of word or
- non-word (but also non-space) characters.
- */
- const cursorGroupLeft = view => cursorByGroup(view, !ltrAtCursor(view));
- /**
- Move the selection one group to the right.
- */
- const cursorGroupRight = view => cursorByGroup(view, ltrAtCursor(view));
- /**
- Move the selection one group forward.
- */
- const cursorGroupForward = view => cursorByGroup(view, true);
- /**
- Move the selection one group backward.
- */
- const cursorGroupBackward = view => cursorByGroup(view, false);
- function moveBySubword(view, range, forward) {
- let categorize = view.state.charCategorizer(range.from);
- return view.moveByChar(range, forward, start => {
- let cat = CharCategory.Space, pos = range.from;
- let done = false, sawUpper = false, sawLower = false;
- let step = (next) => {
- if (done)
- return false;
- pos += forward ? next.length : -next.length;
- let nextCat = categorize(next), ahead;
- if (cat == CharCategory.Space)
- cat = nextCat;
- if (cat != nextCat)
- return false;
- if (cat == CharCategory.Word) {
- if (next.toLowerCase() == next) {
- if (!forward && sawUpper)
- return false;
- sawLower = true;
- }
- else if (sawLower) {
- if (forward)
- return false;
- done = true;
- }
- else {
- if (sawUpper && forward && categorize(ahead = view.state.sliceDoc(pos, pos + 1)) == CharCategory.Word &&
- ahead.toLowerCase() == ahead)
- return false;
- sawUpper = true;
- }
- }
- return true;
- };
- step(start);
- return step;
- });
- }
- function cursorBySubword(view, forward) {
- return moveSel(view, range => range.empty ? moveBySubword(view, range, forward) : rangeEnd(range, forward));
- }
- /**
- Move the selection one group or camel-case subword forward.
- */
- const cursorSubwordForward = view => cursorBySubword(view, true);
- /**
- Move the selection one group or camel-case subword backward.
- */
- const cursorSubwordBackward = view => cursorBySubword(view, false);
- function interestingNode(state, node, bracketProp) {
- if (node.type.prop(bracketProp))
- return true;
- let len = node.to - node.from;
- return len && (len > 2 || /[^\s,.;:]/.test(state.sliceDoc(node.from, node.to))) || node.firstChild;
- }
- function moveBySyntax(state, start, forward) {
- let pos = syntaxTree(state).resolveInner(start.head);
- let bracketProp = forward ? NodeProp.closedBy : NodeProp.openedBy;
- // Scan forward through child nodes to see if there's an interesting
- // node ahead.
- for (let at = start.head;;) {
- let next = forward ? pos.childAfter(at) : pos.childBefore(at);
- if (!next)
- break;
- if (interestingNode(state, next, bracketProp))
- pos = next;
- else
- at = forward ? next.to : next.from;
- }
- let bracket = pos.type.prop(bracketProp), match, newPos;
- if (bracket && (match = forward ? matchBrackets(state, pos.from, 1) : matchBrackets(state, pos.to, -1)) && match.matched)
- newPos = forward ? match.end.to : match.end.from;
- else
- newPos = forward ? pos.to : pos.from;
- return EditorSelection.cursor(newPos, forward ? -1 : 1);
- }
- /**
- Move the cursor over the next syntactic element to the left.
- */
- const cursorSyntaxLeft = view => moveSel(view, range => moveBySyntax(view.state, range, !ltrAtCursor(view)));
- /**
- Move the cursor over the next syntactic element to the right.
- */
- const cursorSyntaxRight = view => moveSel(view, range => moveBySyntax(view.state, range, ltrAtCursor(view)));
- function cursorByLine(view, forward) {
- return moveSel(view, range => {
- if (!range.empty)
- return rangeEnd(range, forward);
- let moved = view.moveVertically(range, forward);
- return moved.head != range.head ? moved : view.moveToLineBoundary(range, forward);
- });
- }
- /**
- Move the selection one line up.
- */
- const cursorLineUp = view => cursorByLine(view, false);
- /**
- Move the selection one line down.
- */
- const cursorLineDown = view => cursorByLine(view, true);
- function pageHeight(view) {
- return Math.max(view.defaultLineHeight, Math.min(view.dom.clientHeight, innerHeight) - 5);
- }
- function cursorByPage(view, forward) {
- let { state } = view, selection = updateSel(state.selection, range => {
- return range.empty ? view.moveVertically(range, forward, pageHeight(view)) : rangeEnd(range, forward);
- });
- if (selection.eq(state.selection))
- return false;
- let startPos = view.coordsAtPos(state.selection.main.head);
- let scrollRect = view.scrollDOM.getBoundingClientRect();
- let effect;
- if (startPos && startPos.top > scrollRect.top && startPos.bottom < scrollRect.bottom &&
- startPos.top - scrollRect.top <= view.scrollDOM.scrollHeight - view.scrollDOM.scrollTop - view.scrollDOM.clientHeight)
- effect = EditorView.scrollIntoView(selection.main.head, { y: "start", yMargin: startPos.top - scrollRect.top });
- view.dispatch(setSel(state, selection), { effects: effect });
- return true;
- }
- /**
- Move the selection one page up.
- */
- const cursorPageUp = view => cursorByPage(view, false);
- /**
- Move the selection one page down.
- */
- const cursorPageDown = view => cursorByPage(view, true);
- function moveByLineBoundary(view, start, forward) {
- let line = view.lineBlockAt(start.head), moved = view.moveToLineBoundary(start, forward);
- if (moved.head == start.head && moved.head != (forward ? line.to : line.from))
- moved = view.moveToLineBoundary(start, forward, false);
- if (!forward && moved.head == line.from && line.length) {
- let space = /^\s*/.exec(view.state.sliceDoc(line.from, Math.min(line.from + 100, line.to)))[0].length;
- if (space && start.head != line.from + space)
- moved = EditorSelection.cursor(line.from + space);
- }
- return moved;
- }
- /**
- Move the selection to the next line wrap point, or to the end of
- the line if there isn't one left on this line.
- */
- const cursorLineBoundaryForward = view => moveSel(view, range => moveByLineBoundary(view, range, true));
- /**
- Move the selection to previous line wrap point, or failing that to
- the start of the line. If the line is indented, and the cursor
- isn't already at the end of the indentation, this will move to the
- end of the indentation instead of the start of the line.
- */
- const cursorLineBoundaryBackward = view => moveSel(view, range => moveByLineBoundary(view, range, false));
- /**
- Move the selection to the start of the line.
- */
- const cursorLineStart = view => moveSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).from, 1));
- /**
- Move the selection to the end of the line.
- */
- const cursorLineEnd = view => moveSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).to, -1));
- function toMatchingBracket(state, dispatch, extend) {
- let found = false, selection = updateSel(state.selection, range => {
- let matching = matchBrackets(state, range.head, -1)
- || matchBrackets(state, range.head, 1)
- || (range.head > 0 && matchBrackets(state, range.head - 1, 1))
- || (range.head < state.doc.length && matchBrackets(state, range.head + 1, -1));
- if (!matching || !matching.end)
- return range;
- found = true;
- let head = matching.start.from == range.head ? matching.end.to : matching.end.from;
- return extend ? EditorSelection.range(range.anchor, head) : EditorSelection.cursor(head);
- });
- if (!found)
- return false;
- dispatch(setSel(state, selection));
- return true;
- }
- /**
- Move the selection to the bracket matching the one it is currently
- on, if any.
- */
- const cursorMatchingBracket = ({ state, dispatch }) => toMatchingBracket(state, dispatch, false);
- /**
- Extend the selection to the bracket matching the one the selection
- head is currently on, if any.
- */
- const selectMatchingBracket = ({ state, dispatch }) => toMatchingBracket(state, dispatch, true);
- function extendSel(view, how) {
- let selection = updateSel(view.state.selection, range => {
- let head = how(range);
- return EditorSelection.range(range.anchor, head.head, head.goalColumn);
- });
- if (selection.eq(view.state.selection))
- return false;
- view.dispatch(setSel(view.state, selection));
- return true;
- }
- function selectByChar(view, forward) {
- return extendSel(view, range => view.moveByChar(range, forward));
- }
- /**
- Move the selection head one character to the left, while leaving
- the anchor in place.
- */
- const selectCharLeft = view => selectByChar(view, !ltrAtCursor(view));
- /**
- Move the selection head one character to the right.
- */
- const selectCharRight = view => selectByChar(view, ltrAtCursor(view));
- /**
- Move the selection head one character forward.
- */
- const selectCharForward = view => selectByChar(view, true);
- /**
- Move the selection head one character backward.
- */
- const selectCharBackward = view => selectByChar(view, false);
- function selectByGroup(view, forward) {
- return extendSel(view, range => view.moveByGroup(range, forward));
- }
- /**
- Move the selection head one [group](https://codemirror.net/6/docs/ref/#commands.cursorGroupLeft) to
- the left.
- */
- const selectGroupLeft = view => selectByGroup(view, !ltrAtCursor(view));
- /**
- Move the selection head one group to the right.
- */
- const selectGroupRight = view => selectByGroup(view, ltrAtCursor(view));
- /**
- Move the selection head one group forward.
- */
- const selectGroupForward = view => selectByGroup(view, true);
- /**
- Move the selection head one group backward.
- */
- const selectGroupBackward = view => selectByGroup(view, false);
- function selectBySubword(view, forward) {
- return extendSel(view, range => moveBySubword(view, range, forward));
- }
- /**
- Move the selection head one group or camel-case subword forward.
- */
- const selectSubwordForward = view => selectBySubword(view, true);
- /**
- Move the selection head one group or subword backward.
- */
- const selectSubwordBackward = view => selectBySubword(view, false);
- /**
- Move the selection head over the next syntactic element to the left.
- */
- const selectSyntaxLeft = view => extendSel(view, range => moveBySyntax(view.state, range, !ltrAtCursor(view)));
- /**
- Move the selection head over the next syntactic element to the right.
- */
- const selectSyntaxRight = view => extendSel(view, range => moveBySyntax(view.state, range, ltrAtCursor(view)));
- function selectByLine(view, forward) {
- return extendSel(view, range => view.moveVertically(range, forward));
- }
- /**
- Move the selection head one line up.
- */
- const selectLineUp = view => selectByLine(view, false);
- /**
- Move the selection head one line down.
- */
- const selectLineDown = view => selectByLine(view, true);
- function selectByPage(view, forward) {
- return extendSel(view, range => view.moveVertically(range, forward, pageHeight(view)));
- }
- /**
- Move the selection head one page up.
- */
- const selectPageUp = view => selectByPage(view, false);
- /**
- Move the selection head one page down.
- */
- const selectPageDown = view => selectByPage(view, true);
- /**
- Move the selection head to the next line boundary.
- */
- const selectLineBoundaryForward = view => extendSel(view, range => moveByLineBoundary(view, range, true));
- /**
- Move the selection head to the previous line boundary.
- */
- const selectLineBoundaryBackward = view => extendSel(view, range => moveByLineBoundary(view, range, false));
- /**
- Move the selection head to the start of the line.
- */
- const selectLineStart = view => extendSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).from));
- /**
- Move the selection head to the end of the line.
- */
- const selectLineEnd = view => extendSel(view, range => EditorSelection.cursor(view.lineBlockAt(range.head).to));
- /**
- Move the selection to the start of the document.
- */
- const cursorDocStart = ({ state, dispatch }) => {
- dispatch(setSel(state, { anchor: 0 }));
- return true;
- };
- /**
- Move the selection to the end of the document.
- */
- const cursorDocEnd = ({ state, dispatch }) => {
- dispatch(setSel(state, { anchor: state.doc.length }));
- return true;
- };
- /**
- Move the selection head to the start of the document.
- */
- const selectDocStart = ({ state, dispatch }) => {
- dispatch(setSel(state, { anchor: state.selection.main.anchor, head: 0 }));
- return true;
- };
- /**
- Move the selection head to the end of the document.
- */
- const selectDocEnd = ({ state, dispatch }) => {
- dispatch(setSel(state, { anchor: state.selection.main.anchor, head: state.doc.length }));
- return true;
- };
- /**
- Select the entire document.
- */
- const selectAll = ({ state, dispatch }) => {
- dispatch(state.update({ selection: { anchor: 0, head: state.doc.length }, userEvent: "select" }));
- return true;
- };
- /**
- Expand the selection to cover entire lines.
- */
- const selectLine = ({ state, dispatch }) => {
- let ranges = selectedLineBlocks(state).map(({ from, to }) => EditorSelection.range(from, Math.min(to + 1, state.doc.length)));
- dispatch(state.update({ selection: EditorSelection.create(ranges), userEvent: "select" }));
- return true;
- };
- /**
- Select the next syntactic construct that is larger than the
- selection. Note that this will only work insofar as the language
- [provider](https://codemirror.net/6/docs/ref/#language.language) you use builds up a full
- syntax tree.
- */
- const selectParentSyntax = ({ state, dispatch }) => {
- let selection = updateSel(state.selection, range => {
- var _a;
- let context = syntaxTree(state).resolveInner(range.head, 1);
- while (!((context.from < range.from && context.to >= range.to) ||
- (context.to > range.to && context.from <= range.from) ||
- !((_a = context.parent) === null || _a === void 0 ? void 0 : _a.parent)))
- context = context.parent;
- return EditorSelection.range(context.to, context.from);
- });
- dispatch(setSel(state, selection));
- return true;
- };
- /**
- Simplify the current selection. When multiple ranges are selected,
- reduce it to its main range. Otherwise, if the selection is
- non-empty, convert it to a cursor selection.
- */
- const simplifySelection = ({ state, dispatch }) => {
- let cur = state.selection, selection = null;
- if (cur.ranges.length > 1)
- selection = EditorSelection.create([cur.main]);
- else if (!cur.main.empty)
- selection = EditorSelection.create([EditorSelection.cursor(cur.main.head)]);
- if (!selection)
- return false;
- dispatch(setSel(state, selection));
- return true;
- };
- function deleteBy({ state, dispatch }, by) {
- if (state.readOnly)
- return false;
- let event = "delete.selection";
- let changes = state.changeByRange(range => {
- let { from, to } = range;
- if (from == to) {
- let towards = by(from);
- if (towards < from)
- event = "delete.backward";
- else if (towards > from)
- event = "delete.forward";
- from = Math.min(from, towards);
- to = Math.max(to, towards);
- }
- return from == to ? { range } : { changes: { from, to }, range: EditorSelection.cursor(from) };
- });
- if (changes.changes.empty)
- return false;
- dispatch(state.update(changes, {
- scrollIntoView: true,
- userEvent: event,
- effects: event == "delete.selection" ? EditorView.announce.of(state.phrase("Selection deleted")) : undefined
- }));
- return true;
- }
- function skipAtomic(target, pos, forward) {
- if (target instanceof EditorView)
- for (let ranges of target.state.facet(EditorView.atomicRanges).map(f => f(target)))
- ranges.between(pos, pos, (from, to) => {
- if (from < pos && to > pos)
- pos = forward ? to : from;
- });
- return pos;
- }
- const deleteByChar = (target, forward) => deleteBy(target, pos => {
- let { state } = target, line = state.doc.lineAt(pos), before, targetPos;
- if (!forward && pos > line.from && pos < line.from + 200 &&
- !/[^ \t]/.test(before = line.text.slice(0, pos - line.from))) {
- if (before[before.length - 1] == "\t")
- return pos - 1;
- let col = countColumn(before, state.tabSize), drop = col % getIndentUnit(state) || getIndentUnit(state);
- for (let i = 0; i < drop && before[before.length - 1 - i] == " "; i++)
- pos--;
- targetPos = pos;
- }
- else {
- targetPos = findClusterBreak(line.text, pos - line.from, forward, forward) + line.from;
- if (targetPos == pos && line.number != (forward ? state.doc.lines : 1))
- targetPos += forward ? 1 : -1;
- }
- return skipAtomic(target, targetPos, forward);
- });
- /**
- Delete the selection, or, for cursor selections, the character
- before the cursor.
- */
- const deleteCharBackward = view => deleteByChar(view, false);
- /**
- Delete the selection or the character after the cursor.
- */
- const deleteCharForward = view => deleteByChar(view, true);
- const deleteByGroup = (target, forward) => deleteBy(target, start => {
- let pos = start, { state } = target, line = state.doc.lineAt(pos);
- let categorize = state.charCategorizer(pos);
- for (let cat = null;;) {
- if (pos == (forward ? line.to : line.from)) {
- if (pos == start && line.number != (forward ? state.doc.lines : 1))
- pos += forward ? 1 : -1;
- break;
- }
- let next = findClusterBreak(line.text, pos - line.from, forward) + line.from;
- let nextChar = line.text.slice(Math.min(pos, next) - line.from, Math.max(pos, next) - line.from);
- let nextCat = categorize(nextChar);
- if (cat != null && nextCat != cat)
- break;
- if (nextChar != " " || pos != start)
- cat = nextCat;
- pos = next;
- }
- return skipAtomic(target, pos, forward);
- });
- /**
- Delete the selection or backward until the end of the next
- [group](https://codemirror.net/6/docs/ref/#view.EditorView.moveByGroup), only skipping groups of
- whitespace when they consist of a single space.
- */
- const deleteGroupBackward = target => deleteByGroup(target, false);
- /**
- Delete the selection or forward until the end of the next group.
- */
- const deleteGroupForward = target => deleteByGroup(target, true);
- /**
- Delete the selection, or, if it is a cursor selection, delete to
- the end of the line. If the cursor is directly at the end of the
- line, delete the line break after it.
- */
- const deleteToLineEnd = view => deleteBy(view, pos => {
- let lineEnd = view.lineBlockAt(pos).to;
- return skipAtomic(view, pos < lineEnd ? lineEnd : Math.min(view.state.doc.length, pos + 1), true);
- });
- /**
- Delete the selection, or, if it is a cursor selection, delete to
- the start of the line. If the cursor is directly at the start of the
- line, delete the line break before it.
- */
- const deleteToLineStart = view => deleteBy(view, pos => {
- let lineStart = view.lineBlockAt(pos).from;
- return skipAtomic(view, pos > lineStart ? lineStart : Math.max(0, pos - 1), false);
- });
- /**
- Delete all whitespace directly before a line end from the
- document.
- */
- const deleteTrailingWhitespace = ({ state, dispatch }) => {
- if (state.readOnly)
- return false;
- let changes = [];
- for (let pos = 0, prev = "", iter = state.doc.iter();;) {
- iter.next();
- if (iter.lineBreak || iter.done) {
- let trailing = prev.search(/\s+$/);
- if (trailing > -1)
- changes.push({ from: pos - (prev.length - trailing), to: pos });
- if (iter.done)
- break;
- prev = "";
- }
- else {
- prev = iter.value;
- }
- pos += iter.value.length;
- }
- if (!changes.length)
- return false;
- dispatch(state.update({ changes, userEvent: "delete" }));
- return true;
- };
- /**
- Replace each selection range with a line break, leaving the cursor
- on the line before the break.
- */
- const splitLine = ({ state, dispatch }) => {
- if (state.readOnly)
- return false;
- let changes = state.changeByRange(range => {
- return { changes: { from: range.from, to: range.to, insert: Text.of(["", ""]) },
- range: EditorSelection.cursor(range.from) };
- });
- dispatch(state.update(changes, { scrollIntoView: true, userEvent: "input" }));
- return true;
- };
- /**
- Flip the characters before and after the cursor(s).
- */
- const transposeChars = ({ state, dispatch }) => {
- if (state.readOnly)
- return false;
- let changes = state.changeByRange(range => {
- if (!range.empty || range.from == 0 || range.from == state.doc.length)
- return { range };
- let pos = range.from, line = state.doc.lineAt(pos);
- let from = pos == line.from ? pos - 1 : findClusterBreak(line.text, pos - line.from, false) + line.from;
- let to = pos == line.to ? pos + 1 : findClusterBreak(line.text, pos - line.from, true) + line.from;
- return { changes: { from, to, insert: state.doc.slice(pos, to).append(state.doc.slice(from, pos)) },
- range: EditorSelection.cursor(to) };
- });
- if (changes.changes.empty)
- return false;
- dispatch(state.update(changes, { scrollIntoView: true, userEvent: "move.character" }));
- return true;
- };
- function selectedLineBlocks(state) {
- let blocks = [], upto = -1;
- for (let range of state.selection.ranges) {
- let startLine = state.doc.lineAt(range.from), endLine = state.doc.lineAt(range.to);
- if (!range.empty && range.to == endLine.from)
- endLine = state.doc.lineAt(range.to - 1);
- if (upto >= startLine.number) {
- let prev = blocks[blocks.length - 1];
- prev.to = endLine.to;
- prev.ranges.push(range);
- }
- else {
- blocks.push({ from: startLine.from, to: endLine.to, ranges: [range] });
- }
- upto = endLine.number + 1;
- }
- return blocks;
- }
- function moveLine(state, dispatch, forward) {
- if (state.readOnly)
- return false;
- let changes = [], ranges = [];
- for (let block of selectedLineBlocks(state)) {
- if (forward ? block.to == state.doc.length : block.from == 0)
- continue;
- let nextLine = state.doc.lineAt(forward ? block.to + 1 : block.from - 1);
- let size = nextLine.length + 1;
- if (forward) {
- changes.push({ from: block.to, to: nextLine.to }, { from: block.from, insert: nextLine.text + state.lineBreak });
- for (let r of block.ranges)
- ranges.push(EditorSelection.range(Math.min(state.doc.length, r.anchor + size), Math.min(state.doc.length, r.head + size)));
- }
- else {
- changes.push({ from: nextLine.from, to: block.from }, { from: block.to, insert: state.lineBreak + nextLine.text });
- for (let r of block.ranges)
- ranges.push(EditorSelection.range(r.anchor - size, r.head - size));
- }
- }
- if (!changes.length)
- return false;
- dispatch(state.update({
- changes,
- scrollIntoView: true,
- selection: EditorSelection.create(ranges, state.selection.mainIndex),
- userEvent: "move.line"
- }));
- return true;
- }
- /**
- Move the selected lines up one line.
- */
- const moveLineUp = ({ state, dispatch }) => moveLine(state, dispatch, false);
- /**
- Move the selected lines down one line.
- */
- const moveLineDown = ({ state, dispatch }) => moveLine(state, dispatch, true);
- function copyLine(state, dispatch, forward) {
- if (state.readOnly)
- return false;
- let changes = [];
- for (let block of selectedLineBlocks(state)) {
- if (forward)
- changes.push({ from: block.from, insert: state.doc.slice(block.from, block.to) + state.lineBreak });
- else
- changes.push({ from: block.to, insert: state.lineBreak + state.doc.slice(block.from, block.to) });
- }
- dispatch(state.update({ changes, scrollIntoView: true, userEvent: "input.copyline" }));
- return true;
- }
- /**
- Create a copy of the selected lines. Keep the selection in the top copy.
- */
- const copyLineUp = ({ state, dispatch }) => copyLine(state, dispatch, false);
- /**
- Create a copy of the selected lines. Keep the selection in the bottom copy.
- */
- const copyLineDown = ({ state, dispatch }) => copyLine(state, dispatch, true);
- /**
- Delete selected lines.
- */
- const deleteLine = view => {
- if (view.state.readOnly)
- return false;
- let { state } = view, changes = state.changes(selectedLineBlocks(state).map(({ from, to }) => {
- if (from > 0)
- from--;
- else if (to < state.doc.length)
- to++;
- return { from, to };
- }));
- let selection = updateSel(state.selection, range => view.moveVertically(range, true)).map(changes);
- view.dispatch({ changes, selection, scrollIntoView: true, userEvent: "delete.line" });
- return true;
- };
- /**
- Replace the selection with a newline.
- */
- const insertNewline = ({ state, dispatch }) => {
- dispatch(state.update(state.replaceSelection(state.lineBreak), { scrollIntoView: true, userEvent: "input" }));
- return true;
- };
- function isBetweenBrackets(state, pos) {
- if (/\(\)|\[\]|\{\}/.test(state.sliceDoc(pos - 1, pos + 1)))
- return { from: pos, to: pos };
- let context = syntaxTree(state).resolveInner(pos);
- let before = context.childBefore(pos), after = context.childAfter(pos), closedBy;
- if (before && after && before.to <= pos && after.from >= pos &&
- (closedBy = before.type.prop(NodeProp.closedBy)) && closedBy.indexOf(after.name) > -1 &&
- state.doc.lineAt(before.to).from == state.doc.lineAt(after.from).from)
- return { from: before.to, to: after.from };
- return null;
- }
- /**
- Replace the selection with a newline and indent the newly created
- line(s). If the current line consists only of whitespace, this
- will also delete that whitespace. When the cursor is between
- matching brackets, an additional newline will be inserted after
- the cursor.
- */
- const insertNewlineAndIndent = /*@__PURE__*/newlineAndIndent(false);
- /**
- Create a blank, indented line below the current line.
- */
- const insertBlankLine = /*@__PURE__*/newlineAndIndent(true);
- function newlineAndIndent(atEof) {
- return ({ state, dispatch }) => {
- if (state.readOnly)
- return false;
- let changes = state.changeByRange(range => {
- let { from, to } = range, line = state.doc.lineAt(from);
- let explode = !atEof && from == to && isBetweenBrackets(state, from);
- if (atEof)
- from = to = (to <= line.to ? line : state.doc.lineAt(to)).to;
- let cx = new IndentContext(state, { simulateBreak: from, simulateDoubleBreak: !!explode });
- let indent = getIndentation(cx, from);
- if (indent == null)
- indent = /^\s*/.exec(state.doc.lineAt(from).text)[0].length;
- while (to < line.to && /\s/.test(line.text[to - line.from]))
- to++;
- if (explode)
- ({ from, to } = explode);
- else if (from > line.from && from < line.from + 100 && !/\S/.test(line.text.slice(0, from)))
- from = line.from;
- let insert = ["", indentString(state, indent)];
- if (explode)
- insert.push(indentString(state, cx.lineIndent(line.from, -1)));
- return { changes: { from, to, insert: Text.of(insert) },
- range: EditorSelection.cursor(from + 1 + insert[1].length) };
- });
- dispatch(state.update(changes, { scrollIntoView: true, userEvent: "input" }));
- return true;
- };
- }
- function changeBySelectedLine(state, f) {
- let atLine = -1;
- return state.changeByRange(range => {
- let changes = [];
- for (let pos = range.from; pos <= range.to;) {
- let line = state.doc.lineAt(pos);
- if (line.number > atLine && (range.empty || range.to > line.from)) {
- f(line, changes, range);
- atLine = line.number;
- }
- pos = line.to + 1;
- }
- let changeSet = state.changes(changes);
- return { changes,
- range: EditorSelection.range(changeSet.mapPos(range.anchor, 1), changeSet.mapPos(range.head, 1)) };
- });
- }
- /**
- Auto-indent the selected lines. This uses the [indentation service
- facet](https://codemirror.net/6/docs/ref/#language.indentService) as source for auto-indent
- information.
- */
- const indentSelection = ({ state, dispatch }) => {
- if (state.readOnly)
- return false;
- let updated = Object.create(null);
- let context = new IndentContext(state, { overrideIndentation: start => {
- let found = updated[start];
- return found == null ? -1 : found;
- } });
- let changes = changeBySelectedLine(state, (line, changes, range) => {
- let indent = getIndentation(context, line.from);
- if (indent == null)
- return;
- if (!/\S/.test(line.text))
- indent = 0;
- let cur = /^\s*/.exec(line.text)[0];
- let norm = indentString(state, indent);
- if (cur != norm || range.from < line.from + cur.length) {
- updated[line.from] = indent;
- changes.push({ from: line.from, to: line.from + cur.length, insert: norm });
- }
- });
- if (!changes.changes.empty)
- dispatch(state.update(changes, { userEvent: "indent" }));
- return true;
- };
- /**
- Add a [unit](https://codemirror.net/6/docs/ref/#language.indentUnit) of indentation to all selected
- lines.
- */
- const indentMore = ({ state, dispatch }) => {
- if (state.readOnly)
- return false;
- dispatch(state.update(changeBySelectedLine(state, (line, changes) => {
- changes.push({ from: line.from, insert: state.facet(indentUnit) });
- }), { userEvent: "input.indent" }));
- return true;
- };
- /**
- Remove a [unit](https://codemirror.net/6/docs/ref/#language.indentUnit) of indentation from all
- selected lines.
- */
- const indentLess = ({ state, dispatch }) => {
- if (state.readOnly)
- return false;
- dispatch(state.update(changeBySelectedLine(state, (line, changes) => {
- let space = /^\s*/.exec(line.text)[0];
- if (!space)
- return;
- let col = countColumn(space, state.tabSize), keep = 0;
- let insert = indentString(state, Math.max(0, col - getIndentUnit(state)));
- while (keep < space.length && keep < insert.length && space.charCodeAt(keep) == insert.charCodeAt(keep))
- keep++;
- changes.push({ from: line.from + keep, to: line.from + space.length, insert: insert.slice(keep) });
- }), { userEvent: "delete.dedent" }));
- return true;
- };
- /**
- Insert a tab character at the cursor or, if something is selected,
- use [`indentMore`](https://codemirror.net/6/docs/ref/#commands.indentMore) to indent the entire
- selection.
- */
- const insertTab = ({ state, dispatch }) => {
- if (state.selection.ranges.some(r => !r.empty))
- return indentMore({ state, dispatch });
- dispatch(state.update(state.replaceSelection("\t"), { scrollIntoView: true, userEvent: "input" }));
- return true;
- };
- /**
- Array of key bindings containing the Emacs-style bindings that are
- available on macOS by default.
- - Ctrl-b: [`cursorCharLeft`](https://codemirror.net/6/docs/ref/#commands.cursorCharLeft) ([`selectCharLeft`](https://codemirror.net/6/docs/ref/#commands.selectCharLeft) with Shift)
- - Ctrl-f: [`cursorCharRight`](https://codemirror.net/6/docs/ref/#commands.cursorCharRight) ([`selectCharRight`](https://codemirror.net/6/docs/ref/#commands.selectCharRight) with Shift)
- - Ctrl-p: [`cursorLineUp`](https://codemirror.net/6/docs/ref/#commands.cursorLineUp) ([`selectLineUp`](https://codemirror.net/6/docs/ref/#commands.selectLineUp) with Shift)
- - Ctrl-n: [`cursorLineDown`](https://codemirror.net/6/docs/ref/#commands.cursorLineDown) ([`selectLineDown`](https://codemirror.net/6/docs/ref/#commands.selectLineDown) with Shift)
- - Ctrl-a: [`cursorLineStart`](https://codemirror.net/6/docs/ref/#commands.cursorLineStart) ([`selectLineStart`](https://codemirror.net/6/docs/ref/#commands.selectLineStart) with Shift)
- - Ctrl-e: [`cursorLineEnd`](https://codemirror.net/6/docs/ref/#commands.cursorLineEnd) ([`selectLineEnd`](https://codemirror.net/6/docs/ref/#commands.selectLineEnd) with Shift)
- - Ctrl-d: [`deleteCharForward`](https://codemirror.net/6/docs/ref/#commands.deleteCharForward)
- - Ctrl-h: [`deleteCharBackward`](https://codemirror.net/6/docs/ref/#commands.deleteCharBackward)
- - Ctrl-k: [`deleteToLineEnd`](https://codemirror.net/6/docs/ref/#commands.deleteToLineEnd)
- - Ctrl-Alt-h: [`deleteGroupBackward`](https://codemirror.net/6/docs/ref/#commands.deleteGroupBackward)
- - Ctrl-o: [`splitLine`](https://codemirror.net/6/docs/ref/#commands.splitLine)
- - Ctrl-t: [`transposeChars`](https://codemirror.net/6/docs/ref/#commands.transposeChars)
- - Ctrl-v: [`cursorPageDown`](https://codemirror.net/6/docs/ref/#commands.cursorPageDown)
- - Alt-v: [`cursorPageUp`](https://codemirror.net/6/docs/ref/#commands.cursorPageUp)
- */
- const emacsStyleKeymap = [
- { key: "Ctrl-b", run: cursorCharLeft, shift: selectCharLeft, preventDefault: true },
- { key: "Ctrl-f", run: cursorCharRight, shift: selectCharRight },
- { key: "Ctrl-p", run: cursorLineUp, shift: selectLineUp },
- { key: "Ctrl-n", run: cursorLineDown, shift: selectLineDown },
- { key: "Ctrl-a", run: cursorLineStart, shift: selectLineStart },
- { key: "Ctrl-e", run: cursorLineEnd, shift: selectLineEnd },
- { key: "Ctrl-d", run: deleteCharForward },
- { key: "Ctrl-h", run: deleteCharBackward },
- { key: "Ctrl-k", run: deleteToLineEnd },
- { key: "Ctrl-Alt-h", run: deleteGroupBackward },
- { key: "Ctrl-o", run: splitLine },
- { key: "Ctrl-t", run: transposeChars },
- { key: "Ctrl-v", run: cursorPageDown },
- ];
- /**
- An array of key bindings closely sticking to platform-standard or
- widely used bindings. (This includes the bindings from
- [`emacsStyleKeymap`](https://codemirror.net/6/docs/ref/#commands.emacsStyleKeymap), with their `key`
- property changed to `mac`.)
- - ArrowLeft: [`cursorCharLeft`](https://codemirror.net/6/docs/ref/#commands.cursorCharLeft) ([`selectCharLeft`](https://codemirror.net/6/docs/ref/#commands.selectCharLeft) with Shift)
- - ArrowRight: [`cursorCharRight`](https://codemirror.net/6/docs/ref/#commands.cursorCharRight) ([`selectCharRight`](https://codemirror.net/6/docs/ref/#commands.selectCharRight) with Shift)
- - Ctrl-ArrowLeft (Alt-ArrowLeft on macOS): [`cursorGroupLeft`](https://codemirror.net/6/docs/ref/#commands.cursorGroupLeft) ([`selectGroupLeft`](https://codemirror.net/6/docs/ref/#commands.selectGroupLeft) with Shift)
- - Ctrl-ArrowRight (Alt-ArrowRight on macOS): [`cursorGroupRight`](https://codemirror.net/6/docs/ref/#commands.cursorGroupRight) ([`selectGroupRight`](https://codemirror.net/6/docs/ref/#commands.selectGroupRight) with Shift)
- - Cmd-ArrowLeft (on macOS): [`cursorLineStart`](https://codemirror.net/6/docs/ref/#commands.cursorLineStart) ([`selectLineStart`](https://codemirror.net/6/docs/ref/#commands.selectLineStart) with Shift)
- - Cmd-ArrowRight (on macOS): [`cursorLineEnd`](https://codemirror.net/6/docs/ref/#commands.cursorLineEnd) ([`selectLineEnd`](https://codemirror.net/6/docs/ref/#commands.selectLineEnd) with Shift)
- - ArrowUp: [`cursorLineUp`](https://codemirror.net/6/docs/ref/#commands.cursorLineUp) ([`selectLineUp`](https://codemirror.net/6/docs/ref/#commands.selectLineUp) with Shift)
- - ArrowDown: [`cursorLineDown`](https://codemirror.net/6/docs/ref/#commands.cursorLineDown) ([`selectLineDown`](https://codemirror.net/6/docs/ref/#commands.selectLineDown) with Shift)
- - Cmd-ArrowUp (on macOS): [`cursorDocStart`](https://codemirror.net/6/docs/ref/#commands.cursorDocStart) ([`selectDocStart`](https://codemirror.net/6/docs/ref/#commands.selectDocStart) with Shift)
- - Cmd-ArrowDown (on macOS): [`cursorDocEnd`](https://codemirror.net/6/docs/ref/#commands.cursorDocEnd) ([`selectDocEnd`](https://codemirror.net/6/docs/ref/#commands.selectDocEnd) with Shift)
- - Ctrl-ArrowUp (on macOS): [`cursorPageUp`](https://codemirror.net/6/docs/ref/#commands.cursorPageUp) ([`selectPageUp`](https://codemirror.net/6/docs/ref/#commands.selectPageUp) with Shift)
- - Ctrl-ArrowDown (on macOS): [`cursorPageDown`](https://codemirror.net/6/docs/ref/#commands.cursorPageDown) ([`selectPageDown`](https://codemirror.net/6/docs/ref/#commands.selectPageDown) with Shift)
- - PageUp: [`cursorPageUp`](https://codemirror.net/6/docs/ref/#commands.cursorPageUp) ([`selectPageUp`](https://codemirror.net/6/docs/ref/#commands.selectPageUp) with Shift)
- - PageDown: [`cursorPageDown`](https://codemirror.net/6/docs/ref/#commands.cursorPageDown) ([`selectPageDown`](https://codemirror.net/6/docs/ref/#commands.selectPageDown) with Shift)
- - Home: [`cursorLineBoundaryBackward`](https://codemirror.net/6/docs/ref/#commands.cursorLineBoundaryBackward) ([`selectLineBoundaryBackward`](https://codemirror.net/6/docs/ref/#commands.selectLineBoundaryBackward) with Shift)
- - End: [`cursorLineBoundaryForward`](https://codemirror.net/6/docs/ref/#commands.cursorLineBoundaryForward) ([`selectLineBoundaryForward`](https://codemirror.net/6/docs/ref/#commands.selectLineBoundaryForward) with Shift)
- - Ctrl-Home (Cmd-Home on macOS): [`cursorDocStart`](https://codemirror.net/6/docs/ref/#commands.cursorDocStart) ([`selectDocStart`](https://codemirror.net/6/docs/ref/#commands.selectDocStart) with Shift)
- - Ctrl-End (Cmd-Home on macOS): [`cursorDocEnd`](https://codemirror.net/6/docs/ref/#commands.cursorDocEnd) ([`selectDocEnd`](https://codemirror.net/6/docs/ref/#commands.selectDocEnd) with Shift)
- - Enter: [`insertNewlineAndIndent`](https://codemirror.net/6/docs/ref/#commands.insertNewlineAndIndent)
- - Ctrl-a (Cmd-a on macOS): [`selectAll`](https://codemirror.net/6/docs/ref/#commands.selectAll)
- - Backspace: [`deleteCharBackward`](https://codemirror.net/6/docs/ref/#commands.deleteCharBackward)
- - Delete: [`deleteCharForward`](https://codemirror.net/6/docs/ref/#commands.deleteCharForward)
- - Ctrl-Backspace (Alt-Backspace on macOS): [`deleteGroupBackward`](https://codemirror.net/6/docs/ref/#commands.deleteGroupBackward)
- - Ctrl-Delete (Alt-Delete on macOS): [`deleteGroupForward`](https://codemirror.net/6/docs/ref/#commands.deleteGroupForward)
- - Cmd-Backspace (macOS): [`deleteToLineStart`](https://codemirror.net/6/docs/ref/#commands.deleteToLineStart).
- - Cmd-Delete (macOS): [`deleteToLineEnd`](https://codemirror.net/6/docs/ref/#commands.deleteToLineEnd).
- */
- const standardKeymap = /*@__PURE__*/[
- { key: "ArrowLeft", run: cursorCharLeft, shift: selectCharLeft, preventDefault: true },
- { key: "Mod-ArrowLeft", mac: "Alt-ArrowLeft", run: cursorGroupLeft, shift: selectGroupLeft },
- { mac: "Cmd-ArrowLeft", run: cursorLineBoundaryBackward, shift: selectLineBoundaryBackward },
- { key: "ArrowRight", run: cursorCharRight, shift: selectCharRight, preventDefault: true },
- { key: "Mod-ArrowRight", mac: "Alt-ArrowRight", run: cursorGroupRight, shift: selectGroupRight },
- { mac: "Cmd-ArrowRight", run: cursorLineBoundaryForward, shift: selectLineBoundaryForward },
- { key: "ArrowUp", run: cursorLineUp, shift: selectLineUp, preventDefault: true },
- { mac: "Cmd-ArrowUp", run: cursorDocStart, shift: selectDocStart },
- { mac: "Ctrl-ArrowUp", run: cursorPageUp, shift: selectPageUp },
- { key: "ArrowDown", run: cursorLineDown, shift: selectLineDown, preventDefault: true },
- { mac: "Cmd-ArrowDown", run: cursorDocEnd, shift: selectDocEnd },
- { mac: "Ctrl-ArrowDown", run: cursorPageDown, shift: selectPageDown },
- { key: "PageUp", run: cursorPageUp, shift: selectPageUp },
- { key: "PageDown", run: cursorPageDown, shift: selectPageDown },
- { key: "Home", run: cursorLineBoundaryBackward, shift: selectLineBoundaryBackward, preventDefault: true },
- { key: "Mod-Home", run: cursorDocStart, shift: selectDocStart },
- { key: "End", run: cursorLineBoundaryForward, shift: selectLineBoundaryForward, preventDefault: true },
- { key: "Mod-End", run: cursorDocEnd, shift: selectDocEnd },
- { key: "Enter", run: insertNewlineAndIndent },
- { key: "Mod-a", run: selectAll },
- { key: "Backspace", run: deleteCharBackward, shift: deleteCharBackward },
- { key: "Delete", run: deleteCharForward },
- { key: "Mod-Backspace", mac: "Alt-Backspace", run: deleteGroupBackward },
- { key: "Mod-Delete", mac: "Alt-Delete", run: deleteGroupForward },
- { mac: "Mod-Backspace", run: deleteToLineStart },
- { mac: "Mod-Delete", run: deleteToLineEnd }
- ].concat(/*@__PURE__*/emacsStyleKeymap.map(b => ({ mac: b.key, run: b.run, shift: b.shift })));
- /**
- The default keymap. Includes all bindings from
- [`standardKeymap`](https://codemirror.net/6/docs/ref/#commands.standardKeymap) plus the following:
- - Alt-ArrowLeft (Ctrl-ArrowLeft on macOS): [`cursorSyntaxLeft`](https://codemirror.net/6/docs/ref/#commands.cursorSyntaxLeft) ([`selectSyntaxLeft`](https://codemirror.net/6/docs/ref/#commands.selectSyntaxLeft) with Shift)
- - Alt-ArrowRight (Ctrl-ArrowRight on macOS): [`cursorSyntaxRight`](https://codemirror.net/6/docs/ref/#commands.cursorSyntaxRight) ([`selectSyntaxRight`](https://codemirror.net/6/docs/ref/#commands.selectSyntaxRight) with Shift)
- - Alt-ArrowUp: [`moveLineUp`](https://codemirror.net/6/docs/ref/#commands.moveLineUp)
- - Alt-ArrowDown: [`moveLineDown`](https://codemirror.net/6/docs/ref/#commands.moveLineDown)
- - Shift-Alt-ArrowUp: [`copyLineUp`](https://codemirror.net/6/docs/ref/#commands.copyLineUp)
- - Shift-Alt-ArrowDown: [`copyLineDown`](https://codemirror.net/6/docs/ref/#commands.copyLineDown)
- - Escape: [`simplifySelection`](https://codemirror.net/6/docs/ref/#commands.simplifySelection)
- - Ctrl-Enter (Comd-Enter on macOS): [`insertBlankLine`](https://codemirror.net/6/docs/ref/#commands.insertBlankLine)
- - Alt-l (Ctrl-l on macOS): [`selectLine`](https://codemirror.net/6/docs/ref/#commands.selectLine)
- - Ctrl-i (Cmd-i on macOS): [`selectParentSyntax`](https://codemirror.net/6/docs/ref/#commands.selectParentSyntax)
- - Ctrl-[ (Cmd-[ on macOS): [`indentLess`](https://codemirror.net/6/docs/ref/#commands.indentLess)
- - Ctrl-] (Cmd-] on macOS): [`indentMore`](https://codemirror.net/6/docs/ref/#commands.indentMore)
- - Ctrl-Alt-\\ (Cmd-Alt-\\ on macOS): [`indentSelection`](https://codemirror.net/6/docs/ref/#commands.indentSelection)
- - Shift-Ctrl-k (Shift-Cmd-k on macOS): [`deleteLine`](https://codemirror.net/6/docs/ref/#commands.deleteLine)
- - Shift-Ctrl-\\ (Shift-Cmd-\\ on macOS): [`cursorMatchingBracket`](https://codemirror.net/6/docs/ref/#commands.cursorMatchingBracket)
- - Ctrl-/ (Cmd-/ on macOS): [`toggleComment`](https://codemirror.net/6/docs/ref/#commands.toggleComment).
- - Shift-Alt-a: [`toggleBlockComment`](https://codemirror.net/6/docs/ref/#commands.toggleBlockComment).
- */
- const defaultKeymap = /*@__PURE__*/[
- { key: "Alt-ArrowLeft", mac: "Ctrl-ArrowLeft", run: cursorSyntaxLeft, shift: selectSyntaxLeft },
- { key: "Alt-ArrowRight", mac: "Ctrl-ArrowRight", run: cursorSyntaxRight, shift: selectSyntaxRight },
- { key: "Alt-ArrowUp", run: moveLineUp },
- { key: "Shift-Alt-ArrowUp", run: copyLineUp },
- { key: "Alt-ArrowDown", run: moveLineDown },
- { key: "Shift-Alt-ArrowDown", run: copyLineDown },
- { key: "Escape", run: simplifySelection },
- { key: "Mod-Enter", run: insertBlankLine },
- { key: "Alt-l", mac: "Ctrl-l", run: selectLine },
- { key: "Mod-i", run: selectParentSyntax, preventDefault: true },
- { key: "Mod-[", run: indentLess },
- { key: "Mod-]", run: indentMore },
- { key: "Mod-Alt-\\", run: indentSelection },
- { key: "Shift-Mod-k", run: deleteLine },
- { key: "Shift-Mod-\\", run: cursorMatchingBracket },
- { key: "Mod-/", run: toggleComment },
- { key: "Alt-A", run: toggleBlockComment }
- ].concat(standardKeymap);
- /**
- A binding that binds Tab to [`indentMore`](https://codemirror.net/6/docs/ref/#commands.indentMore) and
- Shift-Tab to [`indentLess`](https://codemirror.net/6/docs/ref/#commands.indentLess).
- Please see the [Tab example](../../examples/tab/) before using
- this.
- */
- const indentWithTab = { key: "Tab", run: indentMore, shift: indentLess };
- export { blockComment, blockUncomment, copyLineDown, copyLineUp, cursorCharBackward, cursorCharForward, cursorCharLeft, cursorCharRight, cursorDocEnd, cursorDocStart, cursorGroupBackward, cursorGroupForward, cursorGroupLeft, cursorGroupRight, cursorLineBoundaryBackward, cursorLineBoundaryForward, cursorLineDown, cursorLineEnd, cursorLineStart, cursorLineUp, cursorMatchingBracket, cursorPageDown, cursorPageUp, cursorSubwordBackward, cursorSubwordForward, cursorSyntaxLeft, cursorSyntaxRight, defaultKeymap, deleteCharBackward, deleteCharForward, deleteGroupBackward, deleteGroupForward, deleteLine, deleteToLineEnd, deleteToLineStart, deleteTrailingWhitespace, emacsStyleKeymap, history, historyField, historyKeymap, indentLess, indentMore, indentSelection, indentWithTab, insertBlankLine, insertNewline, insertNewlineAndIndent, insertTab, invertedEffects, isolateHistory, lineComment, lineUncomment, moveLineDown, moveLineUp, redo, redoDepth, redoSelection, selectAll, selectCharBackward, selectCharForward, selectCharLeft, selectCharRight, selectDocEnd, selectDocStart, selectGroupBackward, selectGroupForward, selectGroupLeft, selectGroupRight, selectLine, selectLineBoundaryBackward, selectLineBoundaryForward, selectLineDown, selectLineEnd, selectLineStart, selectLineUp, selectMatchingBracket, selectPageDown, selectPageUp, selectParentSyntax, selectSubwordBackward, selectSubwordForward, selectSyntaxLeft, selectSyntaxRight, simplifySelection, splitLine, standardKeymap, toggleBlockComment, toggleBlockCommentByLine, toggleComment, toggleLineComment, transposeChars, undo, undoDepth, undoSelection };
|