Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assorted fixes #479

Merged
merged 5 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
{
"name": "Run Extension",
"type": "extensionHost",
"trace": false,
"request": "launch",
"runtimeExecutable": "${execPath}",
"debugWebviews": true,
Expand All @@ -19,7 +18,7 @@
}
},
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"outFiles": ["${workspaceFolder}/out/**/*.js"]
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
},
{
"name": "Run Web Extension",
Expand Down
2 changes: 1 addition & 1 deletion media/editor/findWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export const FindWidget: React.FC = () => {
clearTimeout(timeout);
}
};
}, [query, JSON.stringify(queryOrError), isUncapped, isCaseSensitive, isBinaryMode, edits.length - safeReplacedEditsLen.current]);
}, [query, JSON.stringify(queryOrError), isUncapped, isCaseSensitive, isBinaryMode, edits.length - safeReplacedEditsLen.current, results.outdated]);

const closeWidget = () => {
const prev = previouslyFocusedElement.current;
Expand Down
4 changes: 4 additions & 0 deletions media/editor/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,10 @@ export const searchResults = atom<SearchResultsWithProgress>({
: { progress: msg.data.progress, capped: msg.data.capped, results: prev.results.concat(msg.data.results) }
);
});

registerHandler(MessageType.ReloadFromDisk, () => {
fx.setSelf(prev => prev instanceof DefaultValue ? prev : ({ ...prev, outdated: true }));
});
}
],
});
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hexeditor",
"displayName": "%name%",
"description": "%description",
"version": "1.9.12",
"version": "1.9.13",
"aiKey": "0c6ae279ed8443289764825290e4f9e2-1a736e7c-1324-4338-be46-fc2a58ae4d14-7255",
"publisher": "ms-vscode",
"repository": {
Expand Down
1 change: 1 addition & 0 deletions shared/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export interface SearchResultsWithProgress {
results: SearchResult[];
progress: number;
capped?: boolean;
outdated?: boolean;
}

export interface SearchProgressMessage {
Expand Down
20 changes: 12 additions & 8 deletions src/fileSystemAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ export const accessFile = async (uri: vscode.Uri, untitledDocumentData?: Uint8Ar
// eslint-disable @typescript-eslint/no-var-requires
const fs = require("fs");
const os = require("os");
// eslint-enable @typescript-eslint/no-var-requires
// eslint-enable @typescript-eslint/no-var-requires

const fileStats = await fs.promises.stat(uri.fsPath);
const { uid, gid } = os.userInfo();

const isReadonly: boolean = (uid === -1 || uid === fileStats.uid) ? !(fileStats.mode & 0o200) : // owner
(gid === fileStats.gid) ? !(fileStats.mode & 0o020) : // group
!(fileStats.mode & 0o002); // other
const isReadonly: boolean = (uid === -1 || uid === fileStats.uid) ? !(fileStats.mode & 0o200) : // owner
(gid === fileStats.gid) ? !(fileStats.mode & 0o020) : // group
!(fileStats.mode & 0o002); // other

if (fileStats.isFile()) {
return new NativeFileAccessor(uri, isReadonly, fs);
Expand Down Expand Up @@ -379,13 +379,17 @@ class DebugFileAccessor implements FileAccessor {
}
}

const watchWorkspaceFile = (uri: string, onDidChange: () => void, onDidDelete: () => void) => {
const watchWorkspaceFile = (uri: string, onDidChange: () => void, onDidDelete: () => void): vscode.Disposable => {
const base = uri.split("/");
const fileName = base.pop()!;
const pattern = new vscode.RelativePattern(vscode.Uri.parse(base.join("/")), fileName);

const watcher = vscode.workspace.createFileSystemWatcher(pattern);
watcher.onDidChange(onDidChange);
watcher.onDidDelete(onDidDelete);
return watcher;
const l1 = watcher.onDidChange(onDidChange);
const l2 = watcher.onDidDelete(onDidDelete);
return new vscode.Disposable(() => {
l1.dispose();
l2.dispose();
watcher.dispose();
});
};
12 changes: 6 additions & 6 deletions src/hexEditorProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ export class HexEditorProvider implements vscode.CustomEditorProvider<HexDocumen
};

const onDidDelete = () => {
vscode.window.showWarningMessage(vscode.l10n.t("This file has been deleted! Saving now will create a new file on disk.", overwrite, vscode.l10n.t("Close Editor"))).then((response) => {
if (response === overwrite) {
vscode.commands.executeCommand("workbench.action.files.save");
} else if (response === "Close Editor") {
vscode.commands.executeCommand("workbench.action.closeActiveEditor");
for (const group of vscode.window.tabGroups.all) {
for (const editor of group.tabs) {
if (editor.input === document) {
vscode.window.tabGroups.close(editor, true);
}
}
});
}
};

disposables.push(accessor.watch(onDidChange, onDidDelete));
Expand Down
17 changes: 8 additions & 9 deletions src/searchRequest.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import { HexDocument } from "./hexDocument";
import { LiteralSearchQuery, RegExpSearchQuery, SearchResult, SearchResultsWithProgress } from "../shared/protocol";
import { Disposable } from "vscode";
import { utf8Length } from "./util";
import { caseInsensitiveEquivalency, LiteralSearch, Wildcard } from "./literalSearch";
import { LiteralSearchQuery, RegExpSearchQuery, SearchResult, SearchResultsWithProgress } from "../shared/protocol";
import { Uint8ArrayMap } from "../shared/util/uint8ArrayMap";
import { HexDocument } from "./hexDocument";
import { LiteralSearch, Wildcard, caseInsensitiveEquivalency } from "./literalSearch";

/** Type that defines a search request created from the {@link SearchProvider} */
export interface ISearchRequest extends Disposable {
Expand All @@ -24,7 +23,7 @@ class ResultsCollector {
constructor(
private readonly filesize: number | undefined,
private cap: number | undefined,
) {}
) { }

public fileOffset = 0;

Expand Down Expand Up @@ -88,7 +87,7 @@ export class LiteralSearchRequest implements ISearchRequest {
const streamSearch = new LiteralSearch(
query.literal.map(c => c === "*" ? Wildcard : c),
(index, data) => collector.push(data, index, index + data.length),
isCaseSensitive ? undefined: caseInsensitiveEquivalency,
isCaseSensitive ? undefined : caseInsensitiveEquivalency,
);

for await (const chunk of document.readWithEdits(0)) {
Expand Down Expand Up @@ -148,7 +147,7 @@ export class RegexSearchRequest implements ISearchRequest {
let strStart = 0;

const { re, document } = this;
const decoder = new TextDecoder();
const decoder = new TextDecoder("ascii");
const encoder = new TextEncoder();
const collector = new ResultsCollector(await document.size(), this.cap);

Expand All @@ -162,8 +161,8 @@ export class RegexSearchRequest implements ISearchRequest {

let lastReIndex = 0;
for (const match of str.matchAll(re)) {
const start = strStart + utf8Length(str.slice(0, match.index!));
const length = utf8Length(match[0]);
const start = strStart + str.slice(0, match.index!).length;
const length = match[0].length;
collector.push(encoder.encode(match[0]), start, start + length);
lastReIndex = match.index! + match[0].length;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/range.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getRangeSelectionsFromStack, Range } from "../../shared/util/range";

describe("Range", () => {

describe.only("getRangeSelectionsFromStack", () => {
describe("getRangeSelectionsFromStack", () => {
it("works for a single", () => {
expect(getRangeSelectionsFromStack([new Range(10, 20)])).to.deep.equal([new Range(10, 20)]);
});
Expand Down
Loading