-
Notifications
You must be signed in to change notification settings - Fork 19
fix(logEventNum): Keyboard navigation shortcuts should update the log event number (fixes #105). #180
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
base: main
Are you sure you want to change the base?
fix(logEventNum): Keyboard navigation shortcuts should update the log event number (fixes #105). #180
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -83,15 +83,24 @@ const Editor = () => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case ACTION_NAME.LAST_PAGE: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| loadPageByAction({code: actionName, args: null}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case ACTION_NAME.PAGE_TOP: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case ACTION_NAME.PAGE_TOP: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| goToPositionAndCenter(editor, {lineNumber: 1, column: 1}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const newlogEventNum = beginLineNumToLogEventNumRef.current.get(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (newlogEventNum) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| updateWindowUrlHashParams({logEventNum: newlogEventNum}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case ACTION_NAME.PAGE_BOTTOM: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const lineCount = editor.getModel()?.getLineCount(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if ("undefined" === typeof lineCount) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| goToPositionAndCenter(editor, {lineNumber: lineCount, column: 1}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const newlogEvent = beginLineNumToLogEventNumRef.current.get(1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (newlogEvent) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| updateWindowUrlHashParams({logEventNum: newlogEvent + pageSizeRef.current - 1}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| break; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Improve error handling and calculation accuracy. The implementation has several areas for improvement:
Apply this diff to address these issues: case ACTION_NAME.PAGE_BOTTOM: {
const lineCount = editor.getModel()?.getLineCount();
if ("undefined" === typeof lineCount) {
break;
}
goToPositionAndCenter(editor, {lineNumber: lineCount, column: 1});
- const newlogEvent = beginLineNumToLogEventNumRef.current.get(1);
- if (newlogEvent) {
- updateWindowUrlHashParams({logEventNum: newlogEvent + pageSizeRef.current - 1});
+ const lastLineLogEventNum = getMapValueWithNearestLessThanOrEqualKey(
+ beginLineNumToLogEventNumRef.current,
+ lineCount
+ );
+ if (!lastLineLogEventNum) {
+ console.error("Unable to find log event number for last line");
+ break;
}
+ updateWindowUrlHashParams({logEventNum: lastLineLogEventNum});
break;
}📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve error handling and variable naming consistency.
The implementation has several areas for improvement:
newlogEventNumshould follow camelCase convention.Apply this diff to address these issues:
case ACTION_NAME.PAGE_TOP: { + const model = editor.getModel(); + if (!model) { + console.error("Editor model is undefined"); + break; + } goToPositionAndCenter(editor, {lineNumber: 1, column: 1}); - const newlogEventNum = beginLineNumToLogEventNumRef.current.get(1); - if (newlogEventNum) { - updateWindowUrlHashParams({logEventNum: newlogEventNum}); + const newLogEventNum = beginLineNumToLogEventNumRef.current.get(1); + if (!newLogEventNum) { + console.error("Unable to find log event number for first line"); + break; } + updateWindowUrlHashParams({logEventNum: newLogEventNum}); break; }