Skip to content

Commit

Permalink
Fix select all only selects the viewport (#842)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanzhong authored Mar 5, 2025
1 parent 6629fdf commit d6299cc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
7 changes: 6 additions & 1 deletion CoreEditor/src/bridge/web/selection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { WebModule } from '../webModule';
import { WebRect } from '../../@types/WebRect';
import { selectedMainText, scrollToSelection, getRect, gotoLine, refreshEditFocus, scrollToBottomSmoothly } from '../../modules/selection';
import { selectWholeDocument, selectedMainText, scrollToSelection, getRect, gotoLine, refreshEditFocus, scrollToBottomSmoothly } from '../../modules/selection';
import { navigateGoBack } from '../../modules/selection/navigate';

/**
Expand All @@ -9,6 +9,7 @@ import { navigateGoBack } from '../../modules/selection/navigate';
* @overrideModuleName WebBridgeSelection
*/
export interface WebModuleSelection extends WebModule {
selectWholeDocument(): void;
getText(): string;
getRect({ pos }: { pos: CodeGen_Int }): WebRect | undefined;
scrollToSelection(): void;
Expand All @@ -19,6 +20,10 @@ export interface WebModuleSelection extends WebModule {
}

export class WebModuleSelectionImpl implements WebModuleSelection {
selectWholeDocument(): void {
selectWholeDocument();
}

getText(): string {
return selectedMainText();
}
Expand Down
5 changes: 5 additions & 0 deletions CoreEditor/src/modules/selection/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { EditorView } from '@codemirror/view';
import { EditorSelection, Line, SelectionRange } from '@codemirror/state';
import { selectAll as selectAllCommand } from '@codemirror/commands';
import { isReleaseMode } from '../../common/utils';
import { almostEqual, afterDomUpdate, getClientRect } from '../../common/utils';

Expand Down Expand Up @@ -47,6 +48,10 @@ export function selectedMainText(): string {
return state.sliceDoc(from, to);
}

export function selectWholeDocument() {
selectAllCommand(window.editor);
}

/**
* Select line based on mouse event, e.g., clicking on gutter number to select the whole line.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public final class WebBridgeSelection {
self.webView = webView
}

public func selectWholeDocument(completion: ((Result<Void, WKWebView.InvokeError>) -> Void)? = nil) {
webView?.invoke(path: "webModules.selection.selectWholeDocument", completion: completion)
}

public func getText() async throws -> String {
return try await withCheckedThrowingContinuation { continuation in
webView?.invoke(path: "webModules.selection.getText") { result in
Expand Down
2 changes: 1 addition & 1 deletion MarkEditMac/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ Gw
</menuItem>
<menuItem title="Select All" keyEquivalent="a" id="Ruw-6m-B2m">
<connections>
<action selector="selectAll:" target="Ady-hI-5gd" id="bET-4d-Oqr"/>
<action selector="selectWholeDocument:" target="Ady-hI-5gd" id="VLu-xb-TLI"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="Ts4-WW-MvM"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,11 @@ private extension EditorViewController {
showGotoLineWindow(sender)
}

@IBAction func selectWholeDocument(_ sender: Any?) {
// The default implementation "selectAll" only selects the viewport
bridge.selection.selectWholeDocument()
}

@IBAction func openTableOfContents(_ sender: Any?) {
if let presentedMenu {
return presentedMenu.cancelTracking()
Expand Down

0 comments on commit d6299cc

Please sign in to comment.