Skip to content

Commit

Permalink
Avoid line break when editing a value while Auto Fit is enabled
Browse files Browse the repository at this point in the history
- Ensure that editing takes as much space as display
- Use CSS to set styles on elements
- Avoid large number of updates by guarding auto-fit group calculation

Fixes #112
  • Loading branch information
martin-fleck-at committed Apr 30, 2024
1 parent 835ef75 commit 4d8eafd
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
37 changes: 37 additions & 0 deletions media/memory-table.css
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@
width: 2px;
}

/* == Hover == */

.hoverable:hover {
border-bottom: 1px dotted var(--vscode-editorHoverWidget-border);
}
Expand Down Expand Up @@ -157,3 +159,38 @@
.memory-hover .variable-hover .value.type {
color: var(--vscode-debugTokenExpression-name);
}

/* == Data Edit == */

.byte-group {
font-family: var(--vscode-editor-font-family);
margin-right: 2px;
padding: 0 1px; /* we use this padding to balance out the 2px that are needed for the editing */
}

.byte-group:last-child {
margin-right: 0px;
}

.byte-group:has(> .data-edit) {
outline: 1px solid var(--vscode-inputOption-activeBorder);
outline-offset: 1px;
padding: 0px; /* editing takes two more pixels cause the input field will cut off the characters otherwise. */
}

.data-edit {
padding: 0;
outline: 0;
border: none;
text-indent: 1px;
min-height: unset;
height: 2ex;
background: unset;
margin: 0;
}

.data-edit:enabled:focus {
outline: none;
border: none;
text-indent: 1px;
}
19 changes: 4 additions & 15 deletions src/webview/columns/data-column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ export class EditableDataColumnRow extends React.Component<EditableDataColumnRow
const next = address + 1n;
if (maus.length % options.mausPerGroup === 0) {
this.applyEndianness(maus, options);
const isLast = next >= range.endAddress;
const style: React.CSSProperties | undefined = isLast ? undefined : DataColumn.Styles.byteGroupStyle;
groups.push(this.renderGroup(maus, groupStartAddress, next, style));
groups.push(this.renderGroup(maus, groupStartAddress, next));
groupStartAddress = next;
maus = [];
}
Expand All @@ -82,12 +80,11 @@ export class EditableDataColumnRow extends React.Component<EditableDataColumnRow
return groups;
}

protected renderGroup(maus: React.ReactNode, startAddress: bigint, endAddress: bigint, style?: React.CSSProperties): React.ReactNode {
protected renderGroup(maus: React.ReactNode, startAddress: bigint, endAddress: bigint): React.ReactNode {
return <span
className='byte-group hoverable'
data-column='data'
data-range={`${startAddress}-${endAddress}`}
style={style}
key={startAddress.toString(16)}
onDoubleClick={this.setGroupEdit}
>
Expand Down Expand Up @@ -138,21 +135,16 @@ export class EditableDataColumnRow extends React.Component<EditableDataColumnRow
}

protected renderEditingGroup(editedRange: BigIntMemoryRange): React.ReactNode {
const isLast = editedRange.endAddress === this.props.range.endAddress;
const defaultValue = this.createEditingGroupDefaultValue(editedRange);

const style: React.CSSProperties = {
...decorationService.getDecoration(editedRange.startAddress)?.style,
width: `calc(${defaultValue.length}ch + 10px)`,
padding: '0 4px',
marginRight: isLast ? undefined : DataColumn.Styles.byteGroupStyle.marginRight,
minHeight: 'unset',
border: '1px solid var(--vscode-inputOption-activeBorder)',
background: 'unset'
width: `calc(${defaultValue.length}ch + 2px)` // we balance the two pixels with padding on the group
};

return <InputText key={editedRange.startAddress.toString(16)}
ref={this.inputText}
className='data-edit'
maxLength={defaultValue.length}
defaultValue={defaultValue}
onBlur={this.onBlur}
Expand Down Expand Up @@ -233,9 +225,6 @@ export class EditableDataColumnRow extends React.Component<EditableDataColumnRow
export namespace DataColumn {
export namespace Styles {
export const MARGIN_RIGHT_PX = 2;
export const byteGroupStyle: React.CSSProperties = {
marginRight: `${DataColumn.Styles.MARGIN_RIGHT_PX}px`
};
}

/**
Expand Down
6 changes: 5 additions & 1 deletion src/webview/components/memory-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,11 @@ export class MemoryTable extends React.PureComponent<MemoryTableProps, MemoryTab
this.setState(prev => ({ ...prev, selection: null }));
}

this.ensureGroupsPerRowToRenderIsSet();
const hasDisplayChanged = prevProps.bytesPerMau !== this.props.bytesPerMau || prevProps.mausPerGroup !== this.props.mausPerGroup ||
(prevProps.groupsPerRow !== 'Autofit' && this.props.groupsPerRow === 'Autofit');
if (hasDisplayChanged) {
this.ensureGroupsPerRowToRenderIsSet();
}
if (this.props.memory !== undefined && this.props.scrollingBehavior === 'Auto-Append') {
this.ensureSufficientVisibleRowsForScrollbar();

Expand Down

0 comments on commit 4d8eafd

Please sign in to comment.