Skip to content
This repository has been archived by the owner on Oct 22, 2020. It is now read-only.

Commit

Permalink
🐛 fix search not wrapping around from the top
Browse files Browse the repository at this point in the history
  • Loading branch information
iliazeus committed Apr 18, 2020
1 parent 1b2f1ca commit 0ee1309
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog

## [1.8.0]
## [1.8.1] 2020-04-19
* Fix searches not wrapping around to the top of the file (stef-levesque#68)

## [1.8.0] 2020-04-18
* Add support for 64-bit integers (thanks @jpihl)
* Add `Copy as Golang` and `Copy as String Literal`
* Fixed `toggleEndian` (stef-levesque#54)
Expand Down Expand Up @@ -106,6 +109,7 @@

* Display a specified file in hexadecimal

[1.8.1]: https://github.com/iliazeus/vscode-hexdump/compare/1b2f1ca797c2275e45f3b6c539e9325b191e48e0...7e5f5fef396c21cb80d5bc3b123272fb124d95f1
[1.8.0]: https://github.com/iliazeus/vscode-hexdump/compare/8544cbd4728b01f91a6495507ba986afd0daf366...d3980d68090c78a05843316ea55e3e03178d12e2
[1.7.2]: https://github.com/iliazeus/vscode-hexdump/compare/30b5275c501e5fcc46004ea31bbb0e5e2a25c38f...00bfca333a5e16602131de78d3590d09ff6421a5
[1.7.1]: https://github.com/iliazeus/vscode-hexdump/compare/83ad82e8503774b61c5118b254fb4fd1b849144f...3306e974af00e954a0d5286c36d26b9f95ae250a
Expand Down
26 changes: 18 additions & 8 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,16 @@ export function activate(context: vscode.ExtensionContext) {

const array = await getContents(d.uri);

var index = Buffer.from(array).indexOf(value, offset, charEncoding);
let index = Buffer.from(array).indexOf(value, offset, charEncoding);

if (index == -1) {
vscode.window.setStatusBarMessage('string not found', 3000);
return;
if (index === -1) {
// wrap the search around from the top
index = Buffer.from(array).indexOf(value, 0, charEncoding);

if (index === -1) {
vscode.window.setStatusBarMessage('string not found', 3000);
return;
}
}

// Translate one to be in the middle of the byte
Expand Down Expand Up @@ -404,11 +409,16 @@ export function activate(context: vscode.ExtensionContext) {
searchBuf.writeUInt8(parseInt(byte, 16), i);
}

const index = Buffer.from(getContents(d.uri)).indexOf(searchBuf, offset);
let index = Buffer.from(getContents(d.uri)).indexOf(searchBuf, offset);

if (index == -1) {
vscode.window.setStatusBarMessage('HEX string not found', 3000);
return;
if (index === -1) {
// wrap the search around from the top
index = Buffer.from(getContents(d.uri)).indexOf(searchBuf, 0);

if (index === -1) {
vscode.window.setStatusBarMessage('HEX string not found', 3000);
return;
}
}

// Translate one to be in the middle of the byte
Expand Down

0 comments on commit 0ee1309

Please sign in to comment.