pi-zentui 0.27.0 → 0.27.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/extensions/zentui/ui.ts +51 -13
- package/package.json +1 -1
package/extensions/zentui/ui.ts
CHANGED
|
@@ -64,6 +64,7 @@ type AutocompleteListInternals = Pick<Component, "render">;
|
|
|
64
64
|
type AutocompleteEditorInternals = {
|
|
65
65
|
autocompleteList?: AutocompleteListInternals;
|
|
66
66
|
isShowingAutocomplete?: () => boolean;
|
|
67
|
+
getPaddingX?: () => number;
|
|
67
68
|
};
|
|
68
69
|
|
|
69
70
|
type AutocompleteCapture = {
|
|
@@ -127,6 +128,7 @@ export type PolishedEditorFrameOptions = {
|
|
|
127
128
|
|
|
128
129
|
type PolishedFrameOptions = {
|
|
129
130
|
width: number;
|
|
131
|
+
baseWidth: number;
|
|
130
132
|
baseRendered: string[];
|
|
131
133
|
autocompleteSource: AutocompleteEditorInternals;
|
|
132
134
|
autocompleteCapture?: AutocompleteCapture;
|
|
@@ -151,6 +153,7 @@ type PolishedFrameResult = {
|
|
|
151
153
|
type AccentRailFrameAdapterOptions = {
|
|
152
154
|
codexQuota?: CodexQuota;
|
|
153
155
|
width: number;
|
|
156
|
+
baseWidth: number;
|
|
154
157
|
baseRendered: string[];
|
|
155
158
|
autocompleteSource: AutocompleteEditorInternals;
|
|
156
159
|
autocompleteCapture?: AutocompleteCapture;
|
|
@@ -162,6 +165,7 @@ type AccentRailFrameAdapterOptions = {
|
|
|
162
165
|
|
|
163
166
|
type MinimalistFrameAdapterOptions = {
|
|
164
167
|
width: number;
|
|
168
|
+
baseWidth: number;
|
|
165
169
|
baseRendered: string[];
|
|
166
170
|
autocompleteSource: AutocompleteEditorInternals;
|
|
167
171
|
autocompleteCapture?: AutocompleteCapture;
|
|
@@ -204,10 +208,25 @@ function stripNativeRightPadding(value: string): string {
|
|
|
204
208
|
return value.replace(/ +$/, "");
|
|
205
209
|
}
|
|
206
210
|
|
|
211
|
+
// Mirrors the native editor's per-render padding clamp: effective horizontal
|
|
212
|
+
// padding never exceeds half of the rendered width.
|
|
213
|
+
function nativeHorizontalPadding(source: AutocompleteEditorInternals, baseWidth: number): number {
|
|
214
|
+
try {
|
|
215
|
+
if (typeof source.getPaddingX !== "function") return 0;
|
|
216
|
+
const padding = source.getPaddingX.call(source);
|
|
217
|
+
if (!Number.isFinite(padding)) return 0;
|
|
218
|
+
const maxPadding = Math.max(0, Math.floor((baseWidth - 1) / 2));
|
|
219
|
+
return Math.min(Math.max(0, Math.floor(padding)), maxPadding);
|
|
220
|
+
} catch {
|
|
221
|
+
return 0;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
207
225
|
function autocompleteCount(
|
|
208
226
|
source: AutocompleteEditorInternals,
|
|
209
227
|
capture: AutocompleteCapture | undefined,
|
|
210
228
|
baseRendered: string[],
|
|
229
|
+
baseWidth: number,
|
|
211
230
|
): AutocompleteCount {
|
|
212
231
|
try {
|
|
213
232
|
const showing = source.isShowingAutocomplete;
|
|
@@ -219,13 +238,18 @@ function autocompleteCount(
|
|
|
219
238
|
capture.rows.length >= baseRendered.length
|
|
220
239
|
)
|
|
221
240
|
return { known: false };
|
|
241
|
+
const paddingX = nativeHorizontalPadding(source, baseWidth);
|
|
242
|
+
const leftPadding = " ".repeat(paddingX);
|
|
222
243
|
const suffix = baseRendered.slice(-capture.rows.length);
|
|
223
244
|
if (
|
|
224
245
|
!suffix.every((line, index) => {
|
|
225
246
|
const captured = capture.rows[index];
|
|
247
|
+
const unpadded =
|
|
248
|
+
paddingX > 0 && line.startsWith(leftPadding) ? line.slice(leftPadding.length) : line;
|
|
226
249
|
return (
|
|
227
250
|
captured !== undefined &&
|
|
228
|
-
(line === captured ||
|
|
251
|
+
(line === captured ||
|
|
252
|
+
stripNativeRightPadding(unpadded) === stripNativeRightPadding(captured))
|
|
229
253
|
);
|
|
230
254
|
})
|
|
231
255
|
)
|
|
@@ -236,6 +260,17 @@ function autocompleteCount(
|
|
|
236
260
|
}
|
|
237
261
|
}
|
|
238
262
|
|
|
263
|
+
// The native editor renders autocomplete rows wrapped in its horizontal
|
|
264
|
+
// padding; prefer the raw captured rows so decoration starts at column zero.
|
|
265
|
+
function capturedAutocompleteLines(
|
|
266
|
+
capture: AutocompleteCapture | undefined,
|
|
267
|
+
baseRendered: string[],
|
|
268
|
+
count: number,
|
|
269
|
+
): string[] {
|
|
270
|
+
if (count <= 0) return [];
|
|
271
|
+
return capture && capture.rows.length === count ? capture.rows : baseRendered.slice(-count);
|
|
272
|
+
}
|
|
273
|
+
|
|
239
274
|
/** @internal Exported only for descriptor-safety regression tests. */
|
|
240
275
|
export function renderWithAutocompleteCapture<T>(
|
|
241
276
|
source: AutocompleteEditorInternals,
|
|
@@ -618,6 +653,7 @@ function readVimStatus(editor: WrappedEditor, uiTheme: Theme): string | undefine
|
|
|
618
653
|
function renderAccentRailFrameFromBase({
|
|
619
654
|
codexQuota,
|
|
620
655
|
width,
|
|
656
|
+
baseWidth,
|
|
621
657
|
baseRendered,
|
|
622
658
|
autocompleteSource,
|
|
623
659
|
autocompleteCapture,
|
|
@@ -634,7 +670,7 @@ function renderAccentRailFrameFromBase({
|
|
|
634
670
|
}
|
|
635
671
|
const autocomplete = ownedFrame
|
|
636
672
|
? { known: true as const, count: ownedFrame.trailingLines.length }
|
|
637
|
-
: autocompleteCount(autocompleteSource, autocompleteCapture, baseRendered);
|
|
673
|
+
: autocompleteCount(autocompleteSource, autocompleteCapture, baseRendered, baseWidth);
|
|
638
674
|
if (!autocomplete.known) {
|
|
639
675
|
return { lines: clampRenderedLines(baseRendered, width), decorated: false };
|
|
640
676
|
}
|
|
@@ -644,9 +680,7 @@ function renderAccentRailFrameFromBase({
|
|
|
644
680
|
: baseRendered;
|
|
645
681
|
const autocompleteLines = ownedFrame
|
|
646
682
|
? ownedFrame.trailingLines
|
|
647
|
-
: autocomplete.count
|
|
648
|
-
? baseRendered.slice(-autocomplete.count)
|
|
649
|
-
: [];
|
|
683
|
+
: capturedAutocompleteLines(autocompleteCapture, baseRendered, autocomplete.count);
|
|
650
684
|
if (editorFrame.length < 2) {
|
|
651
685
|
return { lines: clampRenderedLines(baseRendered, width), decorated: false };
|
|
652
686
|
}
|
|
@@ -695,6 +729,7 @@ function renderAccentRailFrameFromBase({
|
|
|
695
729
|
|
|
696
730
|
function renderMinimalistFrameFromBase({
|
|
697
731
|
width,
|
|
732
|
+
baseWidth,
|
|
698
733
|
baseRendered,
|
|
699
734
|
autocompleteSource,
|
|
700
735
|
autocompleteCapture,
|
|
@@ -715,7 +750,7 @@ function renderMinimalistFrameFromBase({
|
|
|
715
750
|
}
|
|
716
751
|
const autocomplete = ownedFrame
|
|
717
752
|
? { known: true as const, count: ownedFrame.trailingLines.length }
|
|
718
|
-
: autocompleteCount(autocompleteSource, autocompleteCapture, baseRendered);
|
|
753
|
+
: autocompleteCount(autocompleteSource, autocompleteCapture, baseRendered, baseWidth);
|
|
719
754
|
if (!autocomplete.known) {
|
|
720
755
|
return { lines: clampRenderedLines(baseRendered, width), decorated: false };
|
|
721
756
|
}
|
|
@@ -725,9 +760,7 @@ function renderMinimalistFrameFromBase({
|
|
|
725
760
|
: baseRendered;
|
|
726
761
|
const autocompleteLines = ownedFrame
|
|
727
762
|
? ownedFrame.trailingLines
|
|
728
|
-
: autocomplete.count
|
|
729
|
-
? baseRendered.slice(-autocomplete.count)
|
|
730
|
-
: [];
|
|
763
|
+
: capturedAutocompleteLines(autocompleteCapture, baseRendered, autocomplete.count);
|
|
731
764
|
if (editorFrame.length < 2) {
|
|
732
765
|
return { lines: clampRenderedLines(baseRendered, width), decorated: false };
|
|
733
766
|
}
|
|
@@ -771,6 +804,7 @@ function renderMinimalistFrameFromBase({
|
|
|
771
804
|
|
|
772
805
|
function renderPolishedFrame({
|
|
773
806
|
width,
|
|
807
|
+
baseWidth,
|
|
774
808
|
baseRendered,
|
|
775
809
|
autocompleteSource,
|
|
776
810
|
autocompleteCapture,
|
|
@@ -797,7 +831,7 @@ function renderPolishedFrame({
|
|
|
797
831
|
|
|
798
832
|
const autocomplete = ownedFrame
|
|
799
833
|
? { known: true, count: ownedFrame.trailingLines.length }
|
|
800
|
-
: autocompleteCount(autocompleteSource, autocompleteCapture, baseRendered);
|
|
834
|
+
: autocompleteCount(autocompleteSource, autocompleteCapture, baseRendered, baseWidth);
|
|
801
835
|
if (!autocomplete.known) {
|
|
802
836
|
return { lines: clampRenderedLines(baseRendered, width), decorated: false };
|
|
803
837
|
}
|
|
@@ -807,9 +841,7 @@ function renderPolishedFrame({
|
|
|
807
841
|
: baseRendered;
|
|
808
842
|
const autocompleteLines = ownedFrame
|
|
809
843
|
? ownedFrame.trailingLines
|
|
810
|
-
: autocomplete.count
|
|
811
|
-
? baseRendered.slice(-autocomplete.count)
|
|
812
|
-
: [];
|
|
844
|
+
: capturedAutocompleteLines(autocompleteCapture, baseRendered, autocomplete.count);
|
|
813
845
|
if (editorFrame.length < 2) {
|
|
814
846
|
return { lines: clampRenderedLines(baseRendered, width), decorated: false };
|
|
815
847
|
}
|
|
@@ -1124,6 +1156,7 @@ export class PolishedEditor extends CustomEditor {
|
|
|
1124
1156
|
const result = renderAccentRailFrameFromBase({
|
|
1125
1157
|
codexQuota: this.getModelMeta().codexQuota,
|
|
1126
1158
|
width,
|
|
1159
|
+
baseWidth: width - ACCENT_RAIL_CHROME_WIDTH,
|
|
1127
1160
|
baseRendered: captured.value,
|
|
1128
1161
|
autocompleteSource: this as unknown as AutocompleteEditorInternals,
|
|
1129
1162
|
autocompleteCapture: captured.capture,
|
|
@@ -1155,6 +1188,7 @@ export class PolishedEditor extends CustomEditor {
|
|
|
1155
1188
|
try {
|
|
1156
1189
|
const result = renderMinimalistFrameFromBase({
|
|
1157
1190
|
width,
|
|
1191
|
+
baseWidth: Math.max(0, width - 4),
|
|
1158
1192
|
baseRendered: captured.value,
|
|
1159
1193
|
autocompleteSource: this as unknown as AutocompleteEditorInternals,
|
|
1160
1194
|
autocompleteCapture: captured.capture,
|
|
@@ -1193,6 +1227,7 @@ export class PolishedEditor extends CustomEditor {
|
|
|
1193
1227
|
try {
|
|
1194
1228
|
const result = renderPolishedFrame({
|
|
1195
1229
|
width,
|
|
1230
|
+
baseWidth: innerWidth,
|
|
1196
1231
|
baseRendered: captured.value,
|
|
1197
1232
|
autocompleteSource: this as unknown as AutocompleteEditorInternals,
|
|
1198
1233
|
autocompleteCapture: captured.capture,
|
|
@@ -1403,6 +1438,7 @@ export class WrappedPolishedEditor implements EditorComponent {
|
|
|
1403
1438
|
const result = renderAccentRailFrameFromBase({
|
|
1404
1439
|
codexQuota: this.getModelMeta().codexQuota,
|
|
1405
1440
|
width,
|
|
1441
|
+
baseWidth: width - ACCENT_RAIL_CHROME_WIDTH,
|
|
1406
1442
|
baseRendered: captured.value,
|
|
1407
1443
|
autocompleteSource: this.base,
|
|
1408
1444
|
autocompleteCapture: captured.capture,
|
|
@@ -1441,6 +1477,7 @@ export class WrappedPolishedEditor implements EditorComponent {
|
|
|
1441
1477
|
if (provenance.safe) {
|
|
1442
1478
|
const result = renderMinimalistFrameFromBase({
|
|
1443
1479
|
width,
|
|
1480
|
+
baseWidth: Math.max(0, width - 4),
|
|
1444
1481
|
baseRendered: captured.value,
|
|
1445
1482
|
autocompleteSource: this.base,
|
|
1446
1483
|
autocompleteCapture: captured.capture,
|
|
@@ -1486,6 +1523,7 @@ export class WrappedPolishedEditor implements EditorComponent {
|
|
|
1486
1523
|
if (provenance.safe) {
|
|
1487
1524
|
result = renderPolishedFrame({
|
|
1488
1525
|
width,
|
|
1526
|
+
baseWidth: innerWidth,
|
|
1489
1527
|
baseRendered: captured.value,
|
|
1490
1528
|
autocompleteSource: this.base,
|
|
1491
1529
|
autocompleteCapture: captured.capture,
|