Skip to content

Commit

Permalink
fix: respect editor.scrollBeyondLastLine
Browse files Browse the repository at this point in the history
Fixes #329
  • Loading branch information
connor4312 committed Dec 10, 2022
1 parent 2ee2fc1 commit dd032b2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
7 changes: 5 additions & 2 deletions media/editor/scrollContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { css } from "@linaria/core";
import React, { useCallback, useEffect, useRef, useState } from "react";
import { useRecoilState, useRecoilValue } from "recoil";
import { DataDisplay } from "./dataDisplay";
import * as select from "./state";
import { Range } from "./util";
import { DataDisplay } from "./dataDisplay";
import { VirtualScrollContainer } from "./virtualScrollContainer";

const wrapperCls = css`
Expand All @@ -22,6 +22,7 @@ export const ScrollContainer: React.FC = () => {
const dimension = useRecoilValue(select.dimensions);
const columnWidth = useRecoilValue(select.columnWidth);
const fileSize = useRecoilValue(select.fileSize);
const { scrollBeyondLastLine } = useRecoilValue(select.codeSettings);
const [bounds, setBounds] = useRecoilState(select.scrollBounds);
const [offset, setOffset] = useRecoilState(select.offset);
const previousOffset = useRef<number>();
Expand Down Expand Up @@ -64,12 +65,14 @@ export const ScrollContainer: React.FC = () => {
setScrollTop(newScrollTop);
}, [dimension, columnWidth, expandBoundsToContain]);

const extraScroll = scrollBeyondLastLine ? dimension.height / 2 : 0;

return (
<VirtualScrollContainer
className={wrapperCls}
scrollTop={scrollTop}
scrollStart={dimension.rowPxHeight * (bounds.start / columnWidth)}
scrollEnd={dimension.rowPxHeight * (bounds.end / columnWidth) + dimension.height / 2}
scrollEnd={dimension.rowPxHeight * (Math.ceil(bounds.end / columnWidth) + 1) + extraScroll}
onScroll={onScroll}
>
<DataDisplay />
Expand Down
5 changes: 5 additions & 0 deletions media/editor/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ export const isReadonly = selector({
get: ({ get }) => get(readyQuery).isReadonly,
});

export const codeSettings = selector({
key: "codeSettings",
get: ({ get }) => get(readyQuery).codeSettings,
});

export const showReadonlyWarningForEl = atom<HTMLElement | null>({
key: "showReadonlyWarningForEl",
default: null,
Expand Down
5 changes: 5 additions & 0 deletions shared/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,17 @@ export interface IEditorSettings {
defaultEndianness: Endianness;
}

export interface ICodeSettings {
scrollBeyondLastLine: boolean;
}

export interface ReadyResponseMessage {
type: MessageType.ReadyResponse;
initialOffset: number;
pageSize: number;
edits: ISerializedEdits;
editorSettings: IEditorSettings;
codeSettings: ICodeSettings;
unsavedEditIndex: number;
fileSize: number | undefined;
isReadonly: boolean;
Expand Down
10 changes: 9 additions & 1 deletion src/hexEditorProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import TelemetryReporter from "@vscode/extension-telemetry";
import * as base64 from "js-base64";
import * as vscode from "vscode";
import { HexDocumentEditReference } from "../shared/hexDocumentModel";
import { Endianness, ExtensionHostMessageHandler, FromWebviewMessage, IEditorSettings, InspectorLocation, MessageHandler, MessageType, PasteMode, ToWebviewMessage } from "../shared/protocol";
import { Endianness, ExtensionHostMessageHandler, FromWebviewMessage, ICodeSettings, IEditorSettings, InspectorLocation, MessageHandler, MessageType, PasteMode, ToWebviewMessage } from "../shared/protocol";
import { deserializeEdits, serializeEdits } from "../shared/serialization";
import { DataInspectorView } from "./dataInspectorView";
import { disposeAll } from "./dispose";
Expand Down Expand Up @@ -212,6 +212,13 @@ export class HexEditorProvider implements vscode.CustomEditorProvider<HexDocumen
</html>`;
}

private readCodeSettings(): ICodeSettings {
const editorConfig = vscode.workspace.getConfiguration("editor");
return {
scrollBeyondLastLine: editorConfig.get("scrollBeyondLastLine", true)
};
}

private readEditorSettings(): IEditorSettings {
const config = vscode.workspace.getConfiguration("hexeditor");
const settings: IEditorSettings = { ...defaultEditorSettings };
Expand Down Expand Up @@ -250,6 +257,7 @@ export class HexEditorProvider implements vscode.CustomEditorProvider<HexDocumen
type: MessageType.ReadyResponse,
initialOffset: document.baseAddress,
editorSettings: this.readEditorSettings(),
codeSettings: this.readCodeSettings(),
edits: serializeEdits(document.edits),
unsavedEditIndex: document.unsavedEditIndex,
fileSize: await document.size(),
Expand Down

0 comments on commit dd032b2

Please sign in to comment.