@gjsify/gtksource-nativescript 0.64.16 → 0.64.18

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/README.md CHANGED
@@ -1,23 +1,37 @@
1
1
  # @gjsify/gtksource-nativescript
2
2
 
3
- `GtkSource.View` for NativeScript on Android: an `EditText` whose `Editable` carries the syntax
4
- highlight as spans (set in place, re-tokenized per changed line range), a line-number gutter drawn
5
- from the text `Layout` in `onDraw`, and `GtkSource.Buffer` / `LanguageManager` /
6
- `StyleSchemeManager` over `@gjsify/gtksource-core`.
3
+ `GtkSource.View` for NativeScript, with a driver per platform over the same editor logic, and
4
+ `GtkSource.Buffer` / `LanguageManager` / `StyleSchemeManager` over `@gjsify/gtksource-core`:
5
+
6
+ - **Android** — an `EditText` whose `Editable` carries the syntax highlight as spans (set in
7
+ place, re-tokenized per changed line range), with the line-number gutter drawn from the text
8
+ `Layout` in `onDraw`.
9
+ - **iOS** — a `UITextView` whose `NSTextStorage` carries it as attributes on ranges, with the
10
+ gutter drawn in `drawRect:` from the `NSLayoutManager`'s line fragments. `NSTextStorage` has no
11
+ span object a repaint can remove, so a repaint NAMES the range it resets; that arithmetic is
12
+ UIKit-free in `text-ranges.ts` and is the half the specs measure.
13
+
14
+ Shared behaviour and the gaps both halves carry:
7
15
 
8
16
  - No word wrap: every logical line is one layout line, the view scrolls horizontally.
9
17
  - GtkSourceView's `Adwaita` scheme and `def.lang` are LGPL and not bundled. A small own stand-in is
10
18
  registered under `Adwaita` / `Adwaita-dark`; add the real files with `addSchemeFromXml()`.
11
- - `indent-width` is held and read back, not applied: an `EditText` has no indent step. Its only
12
- Tab is a hardware key that inserts `\t`, and `tab-width` would need a `TabStopSpan` per line that
13
- GtkSourceView does not tie to `indent-width`. `auto-indent` copies the previous line's blanks.
19
+ - `indent-width` is held and read back, not applied: neither an `EditText` nor a `UITextView` has
20
+ an indent step. Their only Tab is a hardware key that inserts `\t`, and `tab-width` would need a
21
+ per-line tab stop that GtkSourceView does not tie to `indent-width`. `auto-indent` copies the
22
+ previous line's blanks.
14
23
  - The caret line's number is emphasised only under `highlight-current-line` (default false).
15
24
  - Android API used (R8): the consuming app must keep `android.widget.EditText`, `android.text.*`
16
25
  spans, `android.graphics.Paint`/`Typeface` in its `native-api-usage.json` whitelist. Shared
17
26
  widget classes that come with `@gjsify/adwaita-nativescript` add `android.view.View`
18
27
  (`setTooltipText`, API 26; duck-typed, no `TooltipCompat`) to that list.
19
- - The platform half (`native-editor.android.ts`) ran on a device (API 24 and 36) for `extend-selection` and
20
- `copy-clipboard`. A triple tap selects nothing natively below API 28; see ADR 0094, last amendment.
28
+ - `native-editor.android.ts` ran on a device (API 24 and 36) for `extend-selection` and
29
+ `copy-clipboard`. A triple tap selects nothing natively below API 28; see ADR 0094.
30
+ - `native-editor.ios.ts` has run on NO device and no simulator. It emits neither
31
+ `extend-selection` (the text view's own gesture recognisers offer no documented veto before they
32
+ select) nor `copy-clipboard` (UIKit's `-copy:` editing action collides with `NSObject.copy`), and
33
+ `selectionBackground` has no counterpart there: UIKit derives the selection fill from the
34
+ `tintColor` that also paints the caret. See ADR 0094, last amendment.
21
35
 
22
36
  ## Using it from XML
23
37
 
File without changes
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";import{EditQueue as e,argbComponents as t,clampRange as n,lineAtOffset as r,lineExtent as i,lineStartOffsets as a}from"./text-ranges.js";import{LineStore as o,emphasisedLine as s,gutterWidth as c,visibleLines as l}from"@gjsify/gtksource-core";const u=1e7;function accessoryBar(e){let t=UIToolbar.new();t.frame={origin:{x:0,y:0},size:{width:320,height:44}};let n=UIBarButtonItem.alloc().initWithBarButtonSystemItemTargetAction(UIBarButtonSystemItemFlexibleSpace,null,null),r=UIButton.buttonWithType(UIButtonTypeSystem);r.frame={origin:{x:0,y:0},size:{width:70,height:44}},r.setTitleForState(`Done`,0);let i=UIAction.actionWithTitleImageIdentifierHandler(``,null,null,()=>{e.resignFirstResponder()});return r.addActionForControlEvents(i,UIControlEventTouchUpInside),t.items=[n,UIBarButtonItem.alloc().initWithCustomView(r)],t}let d;function gutterTextView(){return d||(d=UITextView.extend({drawRect(e){let t=this.driver;t?.drawBehind(this),t?.drawGutter(this),this.super.drawRect(e)},layoutSubviews(){this.super.layoutSubviews();let e=this.textContainer;!e.widthTracksTextView&&e.size.width===u||(e.widthTracksTextView=!1,e.size={width:u,height:u})}},{name:`GjsifyGtkSourceTextView`}),d)}let f;function editDelegate(){return f||(f=NSObject.extend({textViewShouldChangeTextInRangeReplacementText(e,t,n){return this.driver?.queueEdit(t,n),!0},textViewDidChange(e){this.driver?.flushEdits()},textViewDidChangeSelection(e){this.driver?.selectionChanged(e.selectedRange)}},{name:`GjsifyGtkSourceTextViewDelegate`,protocols:[UITextViewDelegate]}),f)}function uiColor(e){let{red:n,green:r,blue:i,alpha:a}=t(e);return UIColor.colorWithRedGreenBlueAlpha(n,r,i,a)}function attributed(e,t){return NSAttributedString.alloc().initWithStringAttributes(e,t)}var IosEditorDriver=class{host=null;view=null;delegate=null;applying=!1;queue=new e;pendingText=``;selection={start:0,end:0};lineCount=1;layout=null;palette=null;runs=new o;starts=[0];baseFont=null;traitFonts=new Map;measured=[];appliedGutter=-1;bind(e){this.host=e}createNativeView(e){let t=gutterTextView().new();return t.driver=this,t}attach(e){let t=e;this.view=t,t.opaque=!1;let n=t.textContainer;n.widthTracksTextView=!1,n.lineFragmentPadding=0,n.size={width:u,height:u},t.layoutManager.ensureLayoutForTextContainer(n),t.alwaysBounceHorizontal=!0,t.showsHorizontalScrollIndicator=!0,t.clipsToBounds=!0,this.delegate=editDelegate().new(),this.delegate.driver=this,t.delegate=this.delegate,t.keyboardDismissMode=1,t.inputAccessoryView=accessoryBar(t),this.applyLayout(),this.applyPalette(),this.applying=!0;try{t.text=this.pendingText??``}finally{this.applying=!1}this.pendingText=null,this.refreshStarts(),this.repaintAll(),this.applySelection()}detach(){let e=this.view;e&&(this.pendingText=e.text,e.delegate=null),this.view=null,this.delegate=null,this.queue.clear()}setText(e){if(this.runs.clear(),!this.view){this.pendingText=e,this.refreshStarts();return}this.applying=!0;try{this.view.text=e}finally{this.applying=!1}this.refreshStarts()}replaceRange(e,t,n){let r=this.view;if(!r){let r=this.pendingText??``;this.pendingText=r.slice(0,e)+n+r.slice(t),this.refreshStarts();return}let i=r.textStorage;this.applying=!0;try{i.beginEditing(),i.replaceCharactersInRangeWithString(this.edited(e,t,i.length),n),i.endEditing()}finally{this.applying=!1}this.refreshStarts()}setSelection(e,t){this.selection={start:e,end:t},this.applySelection()}setLineCount(e){this.lineCount=e,this.view&&this.layout?.showLineNumbers&&this.applyLayout()}setLayout(e){this.layout=e,this.applyLayout()}setPalette(e){this.palette=e,this.applyPalette()}edited(e,t,r){let i=Math.min(Math.max(0,Math.min(e,t)),r);return n(i,Math.max(e,t),r)??{location:i,length:0}}refreshStarts(){this.starts=a(this.view?this.view.text:this.pendingText??``)}spliceLines(e,t,n){this.runs.splice(e,t,n)}paintLine(e,t,n){this.runs.set(e,n),this.view&&this.applyRuns(this.view,t,n)}clearAll(){this.runs.clear();let e=this.view;if(!e)return;let t=n(0,e.textStorage.length,e.textStorage.length);t&&e.textStorage.setAttributesRange(this.baseAttributes(),t)}baseAttributes(){let e={};return this.baseFont&&(e[NSFontAttributeName]=this.baseFont),this.palette&&(e[NSForegroundColorAttributeName]=uiColor(this.palette.foreground)),e}runAttributes(e){let t={};if(e.foreground!==void 0&&(t[NSForegroundColorAttributeName]=uiColor(e.foreground)),e.background!==void 0&&(t[NSBackgroundColorAttributeName]=uiColor(e.background)),e.bold||e.italic){let n=this.traitFont((e.bold?2:0)|!!e.italic);n&&(t[NSFontAttributeName]=n)}return e.underline&&(t[NSUnderlineStyleAttributeName]=1),e.strikethrough&&(t[NSStrikethroughStyleAttributeName]=1),Object.keys(t).length>0?t:null}traitFont(e){let t=this.traitFonts.get(e);if(t!==void 0)return t;let n=this.baseFont,r=n?n.fontDescriptor.fontDescriptorWithSymbolicTraits(e):null,i=r?UIFont.fontWithDescriptorSize(r,0):null;return this.traitFonts.set(e,i),i}applyRuns(e,t,r){let a=e.textStorage,o=i(a.string,t);if(!o)return;let s=o.location+o.length;a.beginEditing();try{a.setAttributesRange(this.baseAttributes(),o);for(let e of r){let r=n(t+e.start,t+e.end,s),i=r&&this.runAttributes(e.style);r&&i&&a.addAttributesRange(i,r)}}finally{a.endEditing()}}repaintAll(){let e=this.view;e&&a(e.textStorage.string).forEach((t,n)=>{let r=this.runs.get(n);r&&this.applyRuns(e,t,r)})}applyLayout(){let e=this.view,t=this.layout;if(!e||!t)return;let n=e.font?.pointSize??14;this.baseFont=t.monospace?UIFont.monospacedSystemFontOfSizeWeight(n,0):UIFont.systemFontOfSize(n),this.traitFonts.clear(),e.font=this.baseFont,e.editable=t.editable,e.tintColor=t.cursorVisible?this.caretColor(e):UIColor.clearColor,this.appliedGutter=this.gutterPoints(),e.textContainerInset={top:t.topMargin,left:t.leftMargin+this.appliedGutter,bottom:t.bottomMargin,right:t.rightMargin},e.setNeedsDisplay(),this.repaintAll()}caretColor(e){return this.palette?uiColor(this.palette.foreground):e.tintColor}applyPalette(){let e=this.view,t=this.palette;!e||!t||(e.backgroundColor=uiColor(t.background),e.textColor=uiColor(t.foreground),this.layout?.cursorVisible!==!1&&(e.tintColor=uiColor(t.foreground)),e.setNeedsDisplay(),this.repaintAll())}applySelection(){let e=this.view;if(!e)return;let t=this.edited(this.selection.start,this.selection.end,e.textStorage.length),n=e.selectedRange;if(!(n.location===t.location&&n.length===t.length)){this.applying=!0;try{e.selectedRange=t}finally{this.applying=!1}}}queueEdit(e,t){this.applying||this.queue.push({start:e.location,removed:e.length,inserted:t})}flushEdits(){let e=this.view,t=this.host;if(this.applying||!e||!t||!this.queue.pending)return;this.refreshStarts();for(let e of this.queue.take())t.onNativeEdit(e.start,e.removed,e.inserted);let n=e.selectedRange;t.onNativeSelection(n.location,n.location+n.length)}selectionChanged(e){this.applying||this.queue.pending||(this.selection={start:e.location,end:e.location+e.length},this.host?.onNativeSelection(this.selection.start,this.selection.end),this.view?.setNeedsDisplay())}invalidateGutter(){let e=this.view;e&&(this.gutterPoints()===this.appliedGutter?e.setNeedsDisplay():this.applyLayout())}measureText(e){return attributed(e,this.baseAttributes()).size().width}numbersPoints(e){return this.layout?.showLineNumbers?c(e,this.measureText(`0`),8):0}columnPoints(e,t){return Math.ceil(Math.max(e.widthRequest,t)+e.marginStart+e.marginEnd)}gutterPoints(e=this.lineCount){let t=this.numbersPoints(e);return(this.host?.gutterColumns()??[]).forEach((e,n)=>{t+=this.columnPoints(e,this.measured[n]??0)}),t}fragmentRect(e,t){let n=this.starts;if(t<0||t>=n.length)return null;let r=e.layoutManager,i=n[t];return i>=e.textStorage.length?r.extraLineFragmentRect:r.lineFragmentRectForGlyphAtIndexEffectiveRange(r.glyphIndexForCharacterAtIndex(i),null)}lineTop(e,t){let n=this.fragmentRect(e,t);return n?n.origin.y+e.textContainerInset.top:0}lineBottom(e,t){let n=this.fragmentRect(e,t);return n?n.origin.y+n.size.height+e.textContainerInset.top:0}caretLine(e){let t=e.selectedRange;return r(this.starts,t.location+t.length)}fill(e,t,n,r,i){uiColor(e).setFill(),UIRectFillUsingBlendMode({origin:{x:t,y:n},size:{width:r,height:i}},kCGBlendModeNormal)}draw(e,t,n,r){attributed(e,{...this.baseAttributes(),[NSForegroundColorAttributeName]:uiColor(r)}).drawAtPoint({x:t,y:n})}drawBehind(e){let t=this.palette;if(!t||!this.layout?.highlightCurrentLine||t.currentLineBackground===0)return;let n=this.caretLine(e),r=this.lineTop(e,n),i=this.lineBottom(e,n)-r;i<=0||this.fill(t.currentLineBackground,e.contentOffset.x,r,e.bounds.size.width,i)}drawGutter(e){let t=this.palette,n=this.host;if(!t||!n)return;let r=this.layout?.showLineNumbers===!0,i=this.starts.length,a=e.contentOffset.y,o=l(i,t=>this.lineTop(e,t),t=>this.lineBottom(e,t),a,a+e.bounds.size.height),c=o?n.queryGutter(o.first,o.last):n.gutterColumns().map(e=>({...e,cells:[]}));if(!r&&c.length===0)return;c.forEach((e,t)=>{let n=e.cells.reduce((e,t)=>Math.max(e,this.measureText(t.text)),0);this.measured[t]=Math.max(n,this.measured[t]??0)}),this.measured.length=c.length;let u=this.gutterPoints(i);u!==this.appliedGutter&&(this.appliedGutter=u,setTimeout(()=>this.applyLayout(),0));let d=e.contentOffset.x;if(this.fill(t.lineNumberBackground,d,a,u,e.bounds.size.height),!o)return;let f=s(this.layout?.highlightCurrentLine===!0,this.caretLine(e)),p=d,drawNumbers=()=>{let n=this.numbersPoints(i);for(let r=o.first;r<=o.last;r++){let i=r===f,a=this.lineTop(e,r);i&&t.currentLineNumberBackground!==0&&this.fill(t.currentLineNumberBackground,p,a,n,this.lineBottom(e,r)-a);let o=String(r+1);this.draw(o,p+n-8-this.measureText(o),a,i?t.currentLineNumberForeground:t.lineNumberForeground)}p+=n},m=!r;c.forEach((n,r)=>{!m&&n.position>=0&&(drawNumbers(),m=!0),n.cells.forEach((r,i)=>{r.text!==``&&this.draw(r.text,p+n.marginStart,this.lineTop(e,o.first+i),t.lineNumberForeground)}),p+=this.columnPoints(n,this.measured[r])}),m||drawNumbers()}};function createEditorDriver(){return new IosEditorDriver}export{createEditorDriver};
@@ -0,0 +1,4 @@
1
+ import"./_virtual/_rolldown/runtime.js";function clampRange(e,t,n){let r=Math.min(Math.max(0,e),n),i=Math.min(Math.max(r,t),n);return i>r?{location:r,length:i-r}:null}function lineExtent(e,t){if(t>=e.length)return null;let n=e.indexOf(`
2
+ `,t);return clampRange(t,n<0?e.length:n,e.length)}function lineStartOffsets(e){let t=[0];for(let n=e.indexOf(`
3
+ `);n>=0;n=e.indexOf(`
4
+ `,n+1))t.push(n+1);return t}function lineAtOffset(e,t){let n=0,r=e.length-1;for(;n<r;){let i=n+r+1>>1;e[i]<=t?n=i:r=i-1}return n}function argbComponents(e){return{red:(e>>>16&255)/255,green:(e>>>8&255)/255,blue:(e&255)/255,alpha:(e>>>24&255)/255}}var EditQueue=class{edits=[];get pending(){return this.edits.length>0}push(e){this.edits.push(e)}take(){let e=this.edits;return this.edits=[],e}clear(){this.edits=[]}};export{EditQueue,argbComponents,clampRange,lineAtOffset,lineExtent,lineStartOffsets};
@@ -0,0 +1,140 @@
1
+ export interface CGPoint {
2
+ x: number;
3
+ y: number;
4
+ }
5
+ export interface CGSize {
6
+ width: number;
7
+ height: number;
8
+ }
9
+ export interface CGRect {
10
+ origin: CGPoint;
11
+ size: CGSize;
12
+ }
13
+ /** `NSRange`. UTF-16 code units, so a `location` IS a JS string index. */
14
+ export interface NSRangeValue {
15
+ location: number;
16
+ length: number;
17
+ }
18
+ export interface UIEdgeInsetsValue {
19
+ top: number;
20
+ left: number;
21
+ bottom: number;
22
+ right: number;
23
+ }
24
+ /** An ObjC class as the bridge exposes it: `new` is `+new`, `extend` makes a subclass. */
25
+ export interface ObjCClass<T> {
26
+ new: () => T;
27
+ extend(implementation: object, options?: {
28
+ name?: string;
29
+ protocols?: readonly unknown[];
30
+ }): ObjCClass<T>;
31
+ }
32
+ export interface UIColorInstance {
33
+ /** Makes this the fill colour of the current graphics context, for `UIRectFill`. */
34
+ setFill(): void;
35
+ }
36
+ export interface UIFontDescriptorInstance {
37
+ /** `null` when the family has no face for the traits — a monospace family with no italic. */
38
+ fontDescriptorWithSymbolicTraits(traits: number): UIFontDescriptorInstance | null;
39
+ }
40
+ export interface UIFontInstance {
41
+ readonly pointSize: number;
42
+ readonly fontDescriptor: UIFontDescriptorInstance;
43
+ }
44
+ /** The attribute bag an attributed string takes; the keys are the `NS*AttributeName` globals. */
45
+ export type TextAttributes = Record<string, unknown>;
46
+ export interface NSTextStorageInstance {
47
+ readonly length: number;
48
+ readonly string: string;
49
+ beginEditing(): void;
50
+ endEditing(): void;
51
+ setAttributesRange(attributes: TextAttributes, range: NSRangeValue): void;
52
+ addAttributesRange(attributes: TextAttributes, range: NSRangeValue): void;
53
+ /** The programmatic edit. It does NOT call the text view's delegate, which is why `applying` guards nothing here. */
54
+ replaceCharactersInRangeWithString(range: NSRangeValue, string: string): void;
55
+ }
56
+ export interface NSTextContainerInstance {
57
+ size: CGSize;
58
+ widthTracksTextView: boolean;
59
+ lineFragmentPadding: number;
60
+ }
61
+ export interface NSLayoutManagerInstance {
62
+ readonly numberOfGlyphs: number;
63
+ /** The rect of the trailing empty line; only meaningful when the text ends in a newline. */
64
+ readonly extraLineFragmentRect: CGRect;
65
+ glyphIndexForCharacterAtIndex(index: number): number;
66
+ /** `null` for the out-parameter: this driver never wants the effective glyph range back. */
67
+ lineFragmentRectForGlyphAtIndexEffectiveRange(index: number, effective: null): CGRect;
68
+ locationForGlyphAtIndex(index: number): CGPoint;
69
+ ensureLayoutForTextContainer(container: NSTextContainerInstance): void;
70
+ }
71
+ export interface UIViewNative {
72
+ frame: CGRect;
73
+ bounds: CGRect;
74
+ backgroundColor: UIColorInstance | null;
75
+ opaque: boolean;
76
+ clipsToBounds: boolean;
77
+ /** Set on the views this driver creates, as the Android driver sets it on its `EditText`. */
78
+ driver?: object;
79
+ addSubview(view: UIViewNative): void;
80
+ removeFromSuperview(): void;
81
+ setNeedsDisplay(): void;
82
+ }
83
+ export interface UITextViewNative extends UIViewNative {
84
+ text: string;
85
+ font: UIFontInstance | null;
86
+ textColor: UIColorInstance | null;
87
+ tintColor: UIColorInstance | null;
88
+ editable: boolean;
89
+ selectable: boolean;
90
+ selectedRange: NSRangeValue;
91
+ contentOffset: CGPoint;
92
+ contentSize: CGSize;
93
+ textContainerInset: UIEdgeInsetsValue;
94
+ alwaysBounceHorizontal: boolean;
95
+ showsHorizontalScrollIndicator: boolean;
96
+ readonly textStorage: NSTextStorageInstance;
97
+ readonly textContainer: NSTextContainerInstance;
98
+ /** Reading it pins the view to TextKit 1 — the reason `native-editor.ios.ts` reads it early. */
99
+ readonly layoutManager: NSLayoutManagerInstance;
100
+ delegate: unknown;
101
+ /** `UIScrollViewKeyboardDismissMode`: a `UITextView` IS a `UIScrollView`. */
102
+ keyboardDismissMode: number;
103
+ /** The bar shown above the keyboard; this is how a `UITextView` gets a "Done" button. */
104
+ inputAccessoryView: UIViewNative | null;
105
+ resignFirstResponder(): boolean;
106
+ }
107
+ /** Opaque: this driver only ever puts these into a `UIToolbar.items` array. */
108
+ export interface UIBarButtonItemInstance {
109
+ }
110
+ export interface UIButtonInstance extends UIViewNative {
111
+ setTitleForState(title: string, state: number): void;
112
+ addActionForControlEvents(action: unknown, events: number): void;
113
+ }
114
+ export interface UIToolbarInstance extends UIViewNative {
115
+ items: UIBarButtonItemInstance[] | null;
116
+ sizeToFit(): void;
117
+ setItemsAnimated(items: UIBarButtonItemInstance[], animated: boolean): void;
118
+ }
119
+ /**
120
+ * The measuring and drawing pair the gutter needs, on an object that really carries them.
121
+ *
122
+ * NOT `NSString`: `-sizeWithAttributes:` and `-drawAtPoint:withAttributes:` are UIKit's
123
+ * `NSStringDrawing` CATEGORY on `NSString`, and the NativeScript iOS runtime marshals a JS
124
+ * string as a VALUE — the string it hands ObjC carries no category methods back, so
125
+ * `("1" as NSString).sizeWithAttributes(…)` raises `TypeError: … is not a function`. That
126
+ * throw happened inside a `-drawRect:` override, where the runtime swallows it: the gutter
127
+ * painted nothing at all and reported no error, for as long as the iOS driver existed.
128
+ * `NSAttributedString` is a real bridged object, and the same two verbs sit on it.
129
+ */
130
+ export interface NSAttributedStringInstance {
131
+ drawAtPoint(point: CGPoint): void;
132
+ /**
133
+ * A METHOD, not a property: `NSStringDrawing` declares `- (CGSize)size;`, and the
134
+ * NativeScript bridge only exposes an ObjC `@property` as a JS accessor. Read as a
135
+ * property it answers the function object, `.width` on it is `undefined`, and the `NaN`
136
+ * travels — through `gutterWidth` into `textContainerInset.left`, which UIKit then takes
137
+ * as zero, so the gutter and the text overlap at x=0 with nothing raising an error.
138
+ */
139
+ size(): CGSize;
140
+ }
@@ -0,0 +1,2 @@
1
+ import type { NativeEditorDriver } from './native-editor.js';
2
+ export declare function createEditorDriver(): NativeEditorDriver;
@@ -0,0 +1,50 @@
1
+ /** An `NSRange`, in the shape the ObjC bridge marshals. */
2
+ export interface TextRange {
3
+ readonly location: number;
4
+ readonly length: number;
5
+ }
6
+ /** `[start, end)` clamped into `[0, textLength]`; null when nothing is left to cover. */
7
+ export declare function clampRange(start: number, end: number, textLength: number): TextRange | null;
8
+ /**
9
+ * The range of the line that starts at `lineStart`, without its newline.
10
+ *
11
+ * A repaint resets THIS range to the base attributes and then adds the new runs over it. Reading
12
+ * the extent off the live text rather than remembering what the last pass painted is what keeps it
13
+ * correct through an edit: an offset remembered before an insertion points somewhere else after
14
+ * it, while the line a highlighter is repainting is always the line the text has now.
15
+ */
16
+ export declare function lineExtent(text: string, lineStart: number): TextRange | null;
17
+ /** The offset every logical line starts at; `[0]` for the empty text. */
18
+ export declare function lineStartOffsets(text: string): number[];
19
+ /** The line `offset` falls on, by binary search over `starts`; the last line for anything past the end. */
20
+ export declare function lineAtOffset(starts: readonly number[], offset: number): number;
21
+ /** The components `UIColor` takes, from the `0xAARRGGBB` integer a palette and a run style carry. */
22
+ export declare function argbComponents(argb: number): {
23
+ red: number;
24
+ green: number;
25
+ blue: number;
26
+ alpha: number;
27
+ };
28
+ /** One edit the platform made, as `EditorHost.onNativeEdit` takes it. */
29
+ export interface QueuedEdit {
30
+ readonly start: number;
31
+ readonly removed: number;
32
+ readonly inserted: string;
33
+ }
34
+ /**
35
+ * The edits the platform reported since the last flush, in order.
36
+ *
37
+ * Android queues in `onTextChanged` and flushes in `afterTextChanged`; iOS queues in
38
+ * `textView:shouldChangeTextInRange:replacementText:` and flushes in `textViewDidChange:`. Both
39
+ * platforms can report several edits before the after-callback (autocorrect replaces a word while
40
+ * committing the next one), and the host may edit again from inside the flush — auto-indent does —
41
+ * so the queue is TAKEN rather than iterated in place.
42
+ */
43
+ export declare class EditQueue {
44
+ private edits;
45
+ get pending(): boolean;
46
+ push(edit: QueuedEdit): void;
47
+ /** Empties the queue and returns what it held. */
48
+ take(): readonly QueuedEdit[];
49
+ clear(): void;
50
+ }
@@ -0,0 +1 @@
1
+ export declare const TextRangesTest: () => Promise<void>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gjsify/gtksource-nativescript",
3
- "version": "0.64.16",
4
- "description": "GtkSource.View for NativeScript — an Android EditText with incremental syntax highlighting, a line-number gutter and GtkSourceView language/scheme managers, driven by @gjsify/gtksource-core",
3
+ "version": "0.64.18",
4
+ "description": "GtkSource.View for NativeScript — an Android EditText or an iOS UITextView with incremental syntax highlighting, a line-number gutter and GtkSourceView language/scheme managers, driven by @gjsify/gtksource-core",
5
5
  "type": "module",
6
6
  "module": "lib/esm/index.js",
7
7
  "types": "lib/types/index.d.ts",
@@ -25,18 +25,20 @@
25
25
  "!lib/types/**/*.spec.d.ts"
26
26
  ],
27
27
  "scripts": {
28
- "clear": "gjsify clear lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.trees.gjs.mjs test.trees.node.mjs",
28
+ "clear": "gjsify clear lib tsconfig.tsbuildinfo tsconfig.types.tsbuildinfo test.gjs.mjs test.node.mjs test.trees.gjs.mjs test.trees.node.mjs",
29
29
  "check": "gjsify tsc --noEmit && gjsify run check:consumer",
30
30
  "check:consumer": "gjsify tsc -p tsconfig.consumer.json",
31
31
  "build": "gjsify run build:gjsify && gjsify run build:types",
32
32
  "build:gjsify": "gjsify build --library 'src/**/*.{ts,js}' --exclude 'src/**/*.spec.{mts,ts}' 'src/test.{mts,ts}'",
33
33
  "build:types": "gjsify tsc",
34
- "build:test": "gjsify run build:test:trees:gjs && gjsify run build:test:trees:node",
34
+ "build:test": "gjsify run build:test:gjs && gjsify run build:test:node && gjsify run build:test:trees:gjs && gjsify run build:test:trees:node",
35
+ "build:test:gjs": "gjsify build src/test.mts --app gjs --outfile test.gjs.mjs",
36
+ "build:test:node": "gjsify build src/test.mts --app node --outfile test.node.mjs",
35
37
  "build:test:trees:gjs": "gjsify build src/test.trees.mts --app gjs --no-minify --alias @nativescript/core=@gjsify/adwaita-nativescript/testing/ns-core --outfile test.trees.gjs.mjs",
36
38
  "build:test:trees:node": "gjsify build src/test.trees.mts --app node --no-minify --alias @nativescript/core=@gjsify/adwaita-nativescript/testing/ns-core --outfile test.trees.node.mjs",
37
39
  "test": "gjsify run build:gjsify && gjsify run build:test && gjsify run test:node && gjsify run test:gjs",
38
- "test:gjs": "gjsify run test.trees.gjs.mjs",
39
- "test:node": "node test.trees.node.mjs"
40
+ "test:gjs": "gjsify run test.gjs.mjs && gjsify run test.trees.gjs.mjs",
41
+ "test:node": "node test.node.mjs && node test.trees.node.mjs"
40
42
  },
41
43
  "keywords": [
42
44
  "gjs",
@@ -49,8 +51,8 @@
49
51
  "editor"
50
52
  ],
51
53
  "dependencies": {
52
- "@gjsify/adwaita-nativescript": "^0.64.16",
53
- "@gjsify/gtksource-core": "^0.64.16"
54
+ "@gjsify/adwaita-nativescript": "^0.64.18",
55
+ "@gjsify/gtksource-core": "^0.64.18"
54
56
  },
55
57
  "peerDependencies": {
56
58
  "@nativescript/core": "*"
@@ -61,8 +63,8 @@
61
63
  }
62
64
  },
63
65
  "devDependencies": {
64
- "@gjsify/cli": "^0.64.16",
65
- "@gjsify/unit": "^0.64.16",
66
+ "@gjsify/cli": "^0.64.18",
67
+ "@gjsify/unit": "^0.64.18",
66
68
  "@types/node": "^25.9.2",
67
69
  "typescript": "^6.0.3"
68
70
  },
@@ -75,7 +77,8 @@
75
77
  },
76
78
  "tier": 2,
77
79
  "nativescriptPlatforms": [
78
- "android"
80
+ "android",
81
+ "ios"
79
82
  ]
80
83
  },
81
84
  "license": "MIT",