Файли
openidea/src/editor/core/cm/columnMode.ts
T
l0ng-ai 82b6980a59 feat: Second pass aligning interactions with IntelliJ IDEA (#23)
* feat: Second pass aligning interactions with IntelliJ IDEA

Result tool windows
- Next/Previous Occurrence (⌥⌘↓/↑) across Find, Usages, Problems, TODO,
  Inspection and Hierarchy, with an "N of M" status hint
- Find: reuse the unpinned tab, Pin Tab, source preview, group by file or
  directory, exclude moves to the next result, Rerun
- Usages: tabs with pinning, exclude and preview
- Problems, TODO, Inspection: no autoscroll by default, severity-first sorting,
  context menu with quick fixes and copy description
- Trees: F4/⌘↓ jump to source; speed search Home/End and arrow handling

Find in Files, bookmarks, navigation
- Replace mode: Enter replaces the selection, ⇧⌥Enter replaces all, multi-select
- Pin Window toggle, highlighted read-only preview, search/replace history (⌥↓),
  Alt mnemonics, search context filter (comments / string literals)
- Mnemonic bookmarks (⌥F3, ⌃⇧digit, ⌃digit), ⌘F3 bookmarks popup, descriptions,
  ⌘-click gutter toggles a bookmark
- Select In popup (⌥F1); Recent Locations double-click and Delete;
  Search Everywhere remembers the query per tab

Code insight and refactoring
- Extract/Introduce continue with in-place rename and name suggestions;
  expression and occurrence choosers with live highlighting
- Safe Delete confirms first; numbered Refactor This
- Quick Documentation history, in-popup links and a Documentation tool window;
  Quick Definition switches between targets and shows the whole declaration
- Goto chooser lists symbol names and can pin to the Find window
- Parameter Info Tab/⇧Tab, intention preview, Reformat dialog and summary,
  inlay hint ⌘-click and context menu
- Live templates: Enter moves to the next field, two-step Esc, ⌘J as a lookup,
  language surrounders with mnemonics
- File Structure popup as a filterable tree; Show Usages filter and preview;
  call hierarchy jumps to call sites

Editor
- Paste re-indents each line by default; Move Statement moves whole statements
  in and out of blocks and re-indents
- Type over closing quotes of existing strings; ⌘D/⌘⌫ cover folded regions;
  ⌥⌫ deletes the preceding word
- ⌃G / ⌃⌘G whole-word rules and wrap hint; double-modifier caret cloning
- Visual-column block selection, nested Collapse All, recursive folding,
  fold selection toggle, Go to Matching Brace, gutter drag selects lines,
  sticky line and error stripe clicks, Insert toggles overwrite mode

Run, VCS, workbench
- Gutter icons show the last test result; Modify Run Configuration; test tree
  hides passed tests, context menu and assertion diff
- Stack frames resolve by fully qualified class name; context run chooser
- Inline Smart Step Into
- Git Log multi-select filters, "me" and date range; favourite branches,
  Fetch and tags in the branch popup; stash Keep index and Unstash options
- Terminal tab titles follow the shell; Distraction Free persists; gear menu;
  sticky balloons move to the notifications tool window after a while

* fix(vcs): Label restored local changes as yours after Smart Checkout; name the branch checked out

Conflicts from restoring stashed changes show the user's uncommitted
changes on the left like other operations, and the checkout notification
names the new branch instead of the previous one.

* fix: Close the merge editor on Apply; confirm before terminating a running Run tab

Like IDEA, applying a merge result closes its tab, and closing a Run tab
whose process still runs asks before terminating it (with a Settings
toggle and "Do not ask again").

* fix(terminal): Don't start a new session in the background after closing the last tab

The hidden Terminal window stays mounted, so it reopened a session as soon
as the last tab closed. It now opens the Local tab only once the window is
shown again, as IDEA does.

* fix(vcs): Start the merge result from a three-way merge; close the editor on Apply

The result pane now begins with non-conflicting changes merged and each
conflict showing the base text, resolved from the side panes, instead of
raw conflict markers. Apply now reports success, so the tab closes.

fix(search): Match File Structure filter on word starts

* fix: Limit Smart Step Into to the paused line; drop usages hints on callbacks; show full intention titles

Adapters that list every remaining call in the function (debugpy) made Smart
Step Into fall back to a chooser that offered calls from later lines. Targets
are now narrowed to the calls on the paused line, so they are picked in place.

Anonymous functions and callbacks no longer get a 'no usages' hint, and
intention titles are no longer cut short when there is room for them.

* fix: Undo / Redo from the Edit menu and Find Action use the editor's history

They ran the webview's native undo, which misses programmatic edits such as
templates, completion and refactorings, so nothing happened in the editor.
2026-10-25 09:44:46 +08:00

118 рядки
4.6 KiB
TypeScript
Неформатований Анотація Історія

Цей файл містить неоднозначні символи Юнікоду
Цей файл містить символи Юнікоду, які можна сплутати з іншими символами. Якщо ви вважаєте, що це зроблено навмисно, можете сміливо ігнорувати це попередження. Щоб показати їх, скористайтеся кнопкою Escape.
/**
* Edit › Column Selection Mode (⇧⌘8): while on, a plain mouse drag and
* ⇧+arrows make rectangular (block) selections, one range per line.
*/
import { EditorSelection, Prec, StateEffect, StateField, countColumn, findColumn, type EditorState, type Extension } from "@codemirror/state";
import { EditorView, keymap, rectangularSelection } from "@codemirror/view";
/** A block between two visual columns (tabs expanded) of two lines. */
interface Block {
anchorLine: number;
anchorCol: number;
headLine: number;
headCol: number;
}
interface ColumnState {
on: boolean;
/** The block ⇧+arrows extend; reset by any other selection change. */
block: Block | null;
}
export const setColumnMode = StateEffect.define<boolean>();
const setBlock = StateEffect.define<Block>();
export const columnModeField = StateField.define<ColumnState>({
create: () => ({ on: false, block: null }),
update(value, tr) {
let next = value;
for (const e of tr.effects) {
if (e.is(setColumnMode)) next = { on: e.value, block: null };
else if (e.is(setBlock)) return { ...next, block: e.value };
}
if (next.block && (tr.docChanged || tr.selection)) next = { ...next, block: null };
return next;
},
});
export function isColumnMode(state: EditorState): boolean {
return state.field(columnModeField, false)?.on ?? false;
}
export function toggleColumnMode(view: EditorView): boolean {
view.dispatch({ effects: setColumnMode.of(!isColumnMode(view.state)) });
return true;
}
/** One range per line from the anchor column to the head column (visual columns, clamped to each line). */
export function blockSelection(state: EditorState, b: Block): EditorSelection {
const ranges = [];
const step = b.headLine >= b.anchorLine ? 1 : -1;
const at = (text: string, col: number) => findColumn(text, col, state.tabSize);
for (let n = b.anchorLine; ; n += step) {
const line = state.doc.line(n);
ranges.push(EditorSelection.range(line.from + at(line.text, b.anchorCol), line.from + at(line.text, b.headCol)));
if (n === b.headLine) break;
}
return EditorSelection.create(ranges, ranges.length - 1);
}
/** The visual column one character left / right of `col` (a tab is one step; past the line end, one column). */
export function stepColumn(text: string, col: number, d: number, tabSize: number): number {
if (!d) return col;
const width = countColumn(text, tabSize);
if (d > 0 ? col >= width : col > width) return Math.max(0, col + d);
const pos = findColumn(text, col, tabSize);
const at = countColumn(text, tabSize, pos);
if (d > 0) return at > col ? at : countColumn(text, tabSize, pos + 1);
return pos === 0 ? 0 : countColumn(text, tabSize, pos - 1);
}
/** ⇧+arrow in column mode: moves the block's head by a line / column. */
export function extendBlock(view: EditorView, dLine: number, dCol: number): boolean {
const state = view.state;
const field = state.field(columnModeField, false);
if (!field?.on) return false;
let b = field.block;
if (!b) {
const main = state.selection.main;
const a = state.doc.lineAt(main.anchor);
const h = state.doc.lineAt(main.head);
const col = (text: string, offset: number) => countColumn(text, state.tabSize, offset);
b = { anchorLine: a.number, anchorCol: col(a.text, main.anchor - a.from), headLine: h.number, headCol: col(h.text, main.head - h.from) };
}
const headLine = Math.max(1, Math.min(state.doc.lines, b.headLine + dLine));
const next = { ...b, headLine, headCol: stepColumn(state.doc.line(b.headLine).text, b.headCol, dCol, state.tabSize) };
view.dispatch({
selection: blockSelection(state, next),
effects: setBlock.of(next),
scrollIntoView: true,
userEvent: "select.column",
});
return true;
}
function viewOf(e: MouseEvent): EditorView | null {
return e.target instanceof HTMLElement ? EditorView.findFromDOM(e.target) : null;
}
export const columnModeExtension: Extension = [
columnModeField,
rectangularSelection({
eventFilter: (e) => {
if (e.button !== 0 || e.altKey || e.metaKey || e.ctrlKey) return false;
const view = viewOf(e);
return !!view && isColumnMode(view.state);
},
}),
Prec.high(
keymap.of([
{ key: "Shift-ArrowUp", run: (v) => extendBlock(v, -1, 0) },
{ key: "Shift-ArrowDown", run: (v) => extendBlock(v, 1, 0) },
{ key: "Shift-ArrowLeft", run: (v) => extendBlock(v, 0, -1) },
{ key: "Shift-ArrowRight", run: (v) => extendBlock(v, 0, 1) },
]),
),
EditorView.editorAttributes.compute([columnModeField], (s): Record<string, string> => (isColumnMode(s) ? { class: "cm-openidea-columnMode" } : {})),
];