@gjsify/gtksource-nativescript 0.64.33-next.323 → 0.64.33
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 +5 -1
- package/lib/esm/font-size.js +1 -0
- package/lib/esm/native-editor.android.js +2 -2
- package/lib/esm/native-editor.ios.js +1 -1
- package/lib/esm/native-editor.js +1 -1
- package/lib/esm/view.js +1 -1
- package/lib/types/android-types.d.ts +6 -0
- package/lib/types/font-size.d.ts +1 -0
- package/lib/types/native-editor.android.spec.d.ts +1 -0
- package/lib/types/native-editor.d.ts +2 -0
- package/lib/types/view.d.ts +1 -0
- package/package.json +6 -7
package/README.md
CHANGED
|
@@ -21,8 +21,12 @@ Shared behaviour and the gaps both halves carry:
|
|
|
21
21
|
per-line tab stop that GtkSourceView does not tie to `indent-width`. `auto-indent` copies the
|
|
22
22
|
previous line's blanks.
|
|
23
23
|
- The caret line's number is emphasised only under `highlight-current-line` (default false).
|
|
24
|
+
- Text size: the view is a plain `View`, which keeps the CSS `font-size` and applies it to nothing, so
|
|
25
|
+
the driver does (`setTextSize(COMPLEX_UNIT_SP, …)` on Android, points on iOS). Without a
|
|
26
|
+
`font-size` it is 14.67 (GNOME's 11 pt at 96 dpi), the size the Adwaita theme derives its prose
|
|
27
|
+
from; the `EditText` theme default of 18 sp made code 1.23x the prose. The line numbers follow.
|
|
24
28
|
- Android API used (R8): the consuming app must keep `android.widget.EditText`, `android.text.*`
|
|
25
|
-
spans, `android.graphics.Paint`/`Typeface` in its `native-api-usage.json` whitelist. Shared
|
|
29
|
+
spans, `android.graphics.Paint`/`Typeface` and `android.util.TypedValue` in its `native-api-usage.json` whitelist. Shared
|
|
26
30
|
widget classes that come with `@gjsify/adwaita-nativescript` add `android.view.View`
|
|
27
31
|
(`setTooltipText`, API 26; duck-typed, no `TooltipCompat`) to that list.
|
|
28
32
|
- `native-editor.android.ts` ran on a device (API 24 and 36) for `extend-selection` and
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=14.67;export{e as DEFAULT_FONT_SIZE};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{MultiTap as e}from"./multi-tap.js";import{LineStore as t,emphasisedLine as n,gutterWidth as r,visibleLines as i}from"@gjsify/gtksource-core";let a;function gutterEditText(){return a||(a=android.widget.EditText.extend({onDraw(e){let t=this.driver;t?.drawBehind(this,e),this.super.onDraw(e),t?.drawGutter(this,e)},onSelectionChanged(e,t){this.super.onSelectionChanged(e,t),this.driver?.selectionChanged(e,t)},onTouchEvent(e){return this.driver?.touching(this,e)?!0:this.super.onTouchEvent(e)},performLongClick(){return this.driver?.longPressing(this)?!0:this.super.performLongClick()},onTextContextMenuItem(e){let t=this.driver;return e!==16908321||!t?this.super.onTextContextMenuItem(e):t.copyRequested(()=>this.super.onTextContextMenuItem(e))}}),a)}var AndroidEditorDriver=class{host=null;view=null;applying=!1;queue=[];keyListener=null;pendingText=``;selection={start:0,end:0};lineCount=1;layout=null;palette=null;runs=new t;spans=new t;fillPaint=null;textPaint=null;measured=[];appliedGutter=-1;bind(e){this.host=e}platformCopy=null;copyRequested(e){this.platformCopy=e;try{this.host?.onNativeCopy()}finally{this.platformCopy=null}return!0}copySelection(){let e=this.platformCopy;this.platformCopy=null;let t=this.view;if(!e||!t)return;let{start:n,end:r}=this.selection;e(),(t.getSelectionStart()!==n||t.getSelectionEnd()!==r)&&t.setSelection(n,r)}taps=null;pressAt={x:0,y:0};swallowing=!1;touching(t,n){let{ACTION_DOWN:r,ACTION_UP:i,ACTION_CANCEL:a}=android.view.MotionEvent,o=n.getActionMasked();if(o!==r){let e=this.swallowing;return(o===i||o===a)&&(this.swallowing=!1),e}this.swallowing=!1,this.pressAt={x:n.getX(),y:n.getY()},this.taps??=new e(android.view.ViewConfiguration.getDoubleTapTimeout(),android.view.ViewConfiguration.get(t.getContext()).getScaledDoubleTapSlop());let s=this.taps.press(n.getEventTime(),n.getX(),n.getY());return s<2?!1:(this.swallowing=this.extendSelection(t,s===2?0:1),this.swallowing)}longPressing(e){return this.extendSelection(e,0)}extendSelection(e,t){let n=this.host;if(!n||this.applying)return!1;let r=n.onNativeExtendSelection(t,e.getOffsetForPosition(this.pressAt.x,this.pressAt.y));return r?(e.setSelection(r[0],r[1]),!0):!1}createNativeView(e){let t=new(gutterEditText())(e);return t.driver=this,t}attach(e){let t=e;this.view=t,t.setInputType(android.text.InputType.TYPE_CLASS_TEXT|android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE|android.text.InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS),t.setHorizontallyScrolling(!0),t.setGravity(android.view.Gravity.TOP|android.view.Gravity.START),this.keyListener=t.getKeyListener(),t.addTextChangedListener(new android.text.TextWatcher({beforeTextChanged:()=>{},onTextChanged:(e,t,n,r)=>{this.applying||this.queue.push({start:t,removed:n,inserted:e.subSequence(t,t+r).toString()})},afterTextChanged:()=>this.flushEdits()})),this.applyLayout(),this.applyPalette(),this.applying=!0;try{t.setText(this.pendingText??``)}finally{this.applying=!1}this.pendingText=null,this.repaintAll(),this.applySelection()}detach(){this.view&&(this.pendingText=this.view.getText().toString()),this.view=null,this.spans.clear(),this.queue=[]}setText(e){if(this.removeAllSpans(),this.runs.clear(),!this.view){this.pendingText=e;return}this.applying=!0;try{this.view.setText(e)}finally{this.applying=!1}}replaceRange(e,t,n){let r=this.view;if(!r){let r=this.pendingText??``;this.pendingText=r.slice(0,e)+n+r.slice(t);return}let i=r.getText();this.applying=!0;try{i.replace(e,Math.min(t,i.length()),n)}finally{this.applying=!1}}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()}spliceLines(e,t,n){let r=this.view?.getText();for(let i of this.spans.splice(e,t,n))if(r)for(let e of i)r.removeSpan(e);this.runs.splice(e,t,n)}paintLine(e,t,n){this.runs.set(e,n);let r=this.view?.getText();r&&this.applyRuns(r,e,t,n)}clearAll(){this.removeAllSpans(),this.runs.clear()}removeAllSpans(){let e=this.view?.getText(),t=this.spans.clear();if(e)for(let n of t)for(let t of n)e.removeSpan(t)}repaintAll(){let e=this.view?.getText();if(!e)return;let t=e.toString().split(`
|
|
2
|
-
`),n=0;t.forEach((t,r)=>{let i=this.runs.get(r);i&&this.applyRuns(e,r,n,i),n+=t.length+1})}applyRuns(e,t,n,r){for(let n of this.spans.get(t)??[])e.removeSpan(n);let i=e.length(),a=android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE,{ForegroundColorSpan:o,BackgroundColorSpan:s,StyleSpan:c,UnderlineSpan:l,StrikethroughSpan:u}=android.text.style,d=android.graphics.Typeface,f=[],put=(t,n,r)=>{e.setSpan(t,n,r,a),f.push(t)};for(let e of r){let t=n+e.start,r=Math.min(n+e.end,i);if(t>=r)continue;let{style:a}=e;a.foreground!==void 0&&put(new o(a.foreground),t,r),a.background!==void 0&&put(new s(a.background),t,r),(a.bold||a.italic)&&put(new c(a.bold&&a.italic?d.BOLD_ITALIC:a.bold?d.BOLD:d.ITALIC),t,r),a.underline&&put(new l,t,r),a.strikethrough&&put(new u,t,r)}this.spans.set(t,f)}density(e){return e.getResources().getDisplayMetrics().density}columnPixels(e,t,n){return Math.ceil(Math.max(e.widthRequest*n,t)+(e.marginStart+e.marginEnd)*n)}numbersPixels(e,t){if(!this.layout?.showLineNumbers)return 0;let n=8*this.density(e);return r(t,this.paintFor(e).measureText(`0`),n)}gutterPixels(e,t=this.lineCount){let n=this.density(e),r=this.numbersPixels(e,t);return(this.host?.gutterColumns()??[]).forEach((e,t)=>{r+=this.columnPixels(e,this.measured[t]??0,n)}),r}paintFor(e){return this.textPaint??=new android.graphics.Paint(1),this.textPaint.setTextSize(e.getTextSize()),this.textPaint.setTypeface(e.getTypeface()),this.textPaint.setTextAlign(android.graphics.Paint.Align.RIGHT),this.textPaint}applyLayout(){let e=this.view,t=this.layout;if(!e||!t)return;e.setTypeface(t.monospace?android.graphics.Typeface.MONOSPACE:android.graphics.Typeface.DEFAULT);let n=this.density(e);e.setPadding(Math.round(t.leftMargin*n)+this.gutterPixels(e),Math.round(t.topMargin*n),Math.round(t.rightMargin*n),Math.round(t.bottomMargin*n)),e.setKeyListener(t.editable?this.keyListener:null),e.setCursorVisible(t.cursorVisible),this.appliedGutter=this.gutterPixels(e),e.invalidate()}applyPalette(){let e=this.view,t=this.palette;!e||!t||(e.setBackgroundColor(t.background),e.setTextColor(t.foreground),e.setHighlightColor(t.selectionBackground),e.invalidate())}applySelection(){let e=this.view;if(!e)return;let t=e.getText().length(),n=Math.min(this.selection.start,t);e.getSelectionStart()===n&&e.getSelectionEnd()===Math.min(this.selection.end,t)||e.setSelection(n,Math.min(this.selection.end,t))}flushEdits(){let e=this.view,t=this.host;if(this.applying||!e||!t||this.queue.length===0)return;let n=this.queue;this.queue=[];for(let e of n)t.onNativeEdit(e.start,e.removed,e.inserted);t.onNativeSelection(e.getSelectionStart(),e.getSelectionEnd())}selectionChanged(e,t){this.applying||this.queue.length>0||(this.selection={start:e,end:t},this.host?.onNativeSelection(e,t),this.view?.invalidate())}invalidateGutter(){let e=this.view;e&&(this.gutterPixels(e)===this.appliedGutter?e.invalidate():this.applyLayout())}fill(e,t,n,r,i,a){this.fillPaint??=new android.graphics.Paint(0),this.fillPaint.setColor(t),e.drawRect(n,r,i,a,this.fillPaint)}drawBehind(e,t){let n=this.palette,r=e.getLayout();if(!n||!r||!this.layout?.highlightCurrentLine||n.currentLineBackground===0)return;let i=r.getLineForOffset(e.getSelectionEnd()),a=e.getExtendedPaddingTop();this.fill(t,n.currentLineBackground,e.getScrollX(),a+r.getLineTop(i),e.getScrollX()+e.getWidth(),a+r.getLineBottom(i))}drawGutter(e,t){let r=this.palette,a=e.getLayout(),o=this.host;if(!r||!a||!o)return;let s=this.layout?.showLineNumbers===!0,c=this.density(e),l=e.getScrollY(),u=e.getExtendedPaddingTop(),d=i(a.getLineCount(),e=>u+a.getLineTop(e),e=>u+a.getLineBottom(e),l,l+e.getHeight()),f=d?o.queryGutter(d.first,d.last):o.gutterColumns().map(e=>({...e,cells:[]}));if(!s&&f.length===0)return;let p=this.paintFor(e);f.forEach((e,t)=>{let n=e.cells.reduce((e,t)=>Math.max(e,p.measureText(t.text)),0);this.measured[t]=Math.max(n,this.measured[t]??0)}),this.measured.length=f.length;let m=this.gutterPixels(e,a.getLineCount());m!==this.appliedGutter&&(this.appliedGutter=m,e.post(new java.lang.Runnable({run:()=>this.applyLayout()})));let h=e.getScrollX();if(this.fill(t,r.lineNumberBackground,h,l,h+m,l+e.getHeight()),!d)return;let g=8*c,_=n(this.layout?.highlightCurrentLine===!0,a.getLineForOffset(e.getSelectionEnd())),v=h,drawNumbers=()=>{let n=this.numbersPixels(e,a.getLineCount());p.setTextAlign(android.graphics.Paint.Align.RIGHT);for(let e=d.first;e<=d.last;e++){let i=e===_;i&&r.currentLineNumberBackground!==0&&this.fill(t,r.currentLineNumberBackground,v,u+a.getLineTop(e),v+n,u+a.getLineBottom(e)),p.setColor(i?r.currentLineNumberForeground:r.lineNumberForeground),t.drawText(String(e+1),v+n-g,u+a.getLineBaseline(e),p)}v+=n},y=!s;f.forEach((e,n)=>{!y&&e.position>=0&&(drawNumbers(),y=!0),p.setTextAlign(android.graphics.Paint.Align.LEFT),p.setColor(r.lineNumberForeground),e.cells.forEach((n,r)=>{if(n.text===``)return;let i=u+a.getLineBaseline(d.first+r);t.drawText(n.text,v+e.marginStart*c,i,p)}),v+=this.columnPixels(e,this.measured[n],c)}),y||drawNumbers()}};function createEditorDriver(){return new AndroidEditorDriver}export{createEditorDriver};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import"./font-size.js";import{MultiTap as e}from"./multi-tap.js";import{LineStore as t,emphasisedLine as n,gutterWidth as r,visibleLines as i}from"@gjsify/gtksource-core";let a;function gutterEditText(){return a||(a=android.widget.EditText.extend({onDraw(e){let t=this.driver;t?.drawBehind(this,e),this.super.onDraw(e),t?.drawGutter(this,e)},onSelectionChanged(e,t){this.super.onSelectionChanged(e,t),this.driver?.selectionChanged(e,t)},onTouchEvent(e){return this.driver?.touching(this,e)?!0:this.super.onTouchEvent(e)},performLongClick(){return this.driver?.longPressing(this)?!0:this.super.performLongClick()},onTextContextMenuItem(e){let t=this.driver;return e!==16908321||!t?this.super.onTextContextMenuItem(e):t.copyRequested(()=>this.super.onTextContextMenuItem(e))}}),a)}var AndroidEditorDriver=class{host=null;view=null;applying=!1;queue=[];keyListener=null;pendingText=``;selection={start:0,end:0};lineCount=1;layout=null;fontSize;palette=null;runs=new t;spans=new t;fillPaint=null;textPaint=null;measured=[];appliedGutter=-1;bind(e){this.host=e}platformCopy=null;copyRequested(e){this.platformCopy=e;try{this.host?.onNativeCopy()}finally{this.platformCopy=null}return!0}copySelection(){let e=this.platformCopy;this.platformCopy=null;let t=this.view;if(!e||!t)return;let{start:n,end:r}=this.selection;e(),(t.getSelectionStart()!==n||t.getSelectionEnd()!==r)&&t.setSelection(n,r)}taps=null;pressAt={x:0,y:0};swallowing=!1;touching(t,n){let{ACTION_DOWN:r,ACTION_UP:i,ACTION_CANCEL:a}=android.view.MotionEvent,o=n.getActionMasked();if(o!==r){let e=this.swallowing;return(o===i||o===a)&&(this.swallowing=!1),e}this.swallowing=!1,this.pressAt={x:n.getX(),y:n.getY()},this.taps??=new e(android.view.ViewConfiguration.getDoubleTapTimeout(),android.view.ViewConfiguration.get(t.getContext()).getScaledDoubleTapSlop());let s=this.taps.press(n.getEventTime(),n.getX(),n.getY());return s<2?!1:(this.swallowing=this.extendSelection(t,s===2?0:1),this.swallowing)}longPressing(e){return this.extendSelection(e,0)}extendSelection(e,t){let n=this.host;if(!n||this.applying)return!1;let r=n.onNativeExtendSelection(t,e.getOffsetForPosition(this.pressAt.x,this.pressAt.y));return r?(e.setSelection(r[0],r[1]),!0):!1}createNativeView(e){let t=new(gutterEditText())(e);return t.driver=this,t}attach(e){let t=e;this.view=t,t.setInputType(android.text.InputType.TYPE_CLASS_TEXT|android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE|android.text.InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS),t.setHorizontallyScrolling(!0),t.setGravity(android.view.Gravity.TOP|android.view.Gravity.START),this.keyListener=t.getKeyListener(),t.addTextChangedListener(new android.text.TextWatcher({beforeTextChanged:()=>{},onTextChanged:(e,t,n,r)=>{this.applying||this.queue.push({start:t,removed:n,inserted:e.subSequence(t,t+r).toString()})},afterTextChanged:()=>this.flushEdits()})),this.applyLayout(),this.applyPalette(),this.applying=!0;try{t.setText(this.pendingText??``)}finally{this.applying=!1}this.pendingText=null,this.repaintAll(),this.applySelection()}detach(){this.view&&(this.pendingText=this.view.getText().toString()),this.view=null,this.spans.clear(),this.queue=[]}setText(e){if(this.removeAllSpans(),this.runs.clear(),!this.view){this.pendingText=e;return}this.applying=!0;try{this.view.setText(e)}finally{this.applying=!1}}replaceRange(e,t,n){let r=this.view;if(!r){let r=this.pendingText??``;this.pendingText=r.slice(0,e)+n+r.slice(t);return}let i=r.getText();this.applying=!0;try{i.replace(e,Math.min(t,i.length()),n)}finally{this.applying=!1}}setSelection(e,t){this.selection={start:e,end:t},this.applySelection()}setLineCount(e){this.lineCount=e,this.view&&this.layout?.showLineNumbers&&this.applyLayout()}setFontSize(e){this.fontSize=e,this.applyLayout()}setLayout(e){this.layout=e,this.applyLayout()}setPalette(e){this.palette=e,this.applyPalette()}spliceLines(e,t,n){let r=this.view?.getText();for(let i of this.spans.splice(e,t,n))if(r)for(let e of i)r.removeSpan(e);this.runs.splice(e,t,n)}paintLine(e,t,n){this.runs.set(e,n);let r=this.view?.getText();r&&this.applyRuns(r,e,t,n)}clearAll(){this.removeAllSpans(),this.runs.clear()}removeAllSpans(){let e=this.view?.getText(),t=this.spans.clear();if(e)for(let n of t)for(let t of n)e.removeSpan(t)}repaintAll(){let e=this.view?.getText();if(!e)return;let t=e.toString().split(`
|
|
2
|
+
`),n=0;t.forEach((t,r)=>{let i=this.runs.get(r);i&&this.applyRuns(e,r,n,i),n+=t.length+1})}applyRuns(e,t,n,r){for(let n of this.spans.get(t)??[])e.removeSpan(n);let i=e.length(),a=android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE,{ForegroundColorSpan:o,BackgroundColorSpan:s,StyleSpan:c,UnderlineSpan:l,StrikethroughSpan:u}=android.text.style,d=android.graphics.Typeface,f=[],put=(t,n,r)=>{e.setSpan(t,n,r,a),f.push(t)};for(let e of r){let t=n+e.start,r=Math.min(n+e.end,i);if(t>=r)continue;let{style:a}=e;a.foreground!==void 0&&put(new o(a.foreground),t,r),a.background!==void 0&&put(new s(a.background),t,r),(a.bold||a.italic)&&put(new c(a.bold&&a.italic?d.BOLD_ITALIC:a.bold?d.BOLD:d.ITALIC),t,r),a.underline&&put(new l,t,r),a.strikethrough&&put(new u,t,r)}this.spans.set(t,f)}density(e){return e.getResources().getDisplayMetrics().density}columnPixels(e,t,n){return Math.ceil(Math.max(e.widthRequest*n,t)+(e.marginStart+e.marginEnd)*n)}numbersPixels(e,t){if(!this.layout?.showLineNumbers)return 0;let n=8*this.density(e);return r(t,this.paintFor(e).measureText(`0`),n)}gutterPixels(e,t=this.lineCount){let n=this.density(e),r=this.numbersPixels(e,t);return(this.host?.gutterColumns()??[]).forEach((e,t)=>{r+=this.columnPixels(e,this.measured[t]??0,n)}),r}paintFor(e){return this.textPaint??=new android.graphics.Paint(1),this.textPaint.setTextSize(e.getTextSize()),this.textPaint.setTypeface(e.getTypeface()),this.textPaint.setTextAlign(android.graphics.Paint.Align.RIGHT),this.textPaint}applyLayout(){let e=this.view,t=this.layout;if(!e||!t)return;e.setTypeface(t.monospace?android.graphics.Typeface.MONOSPACE:android.graphics.Typeface.DEFAULT),e.setTextSize(android.util.TypedValue.COMPLEX_UNIT_SP,this.fontSize??14.67);let n=this.density(e);e.setPadding(Math.round(t.leftMargin*n)+this.gutterPixels(e),Math.round(t.topMargin*n),Math.round(t.rightMargin*n),Math.round(t.bottomMargin*n)),e.setKeyListener(t.editable?this.keyListener:null),e.setCursorVisible(t.cursorVisible),this.appliedGutter=this.gutterPixels(e),e.invalidate()}applyPalette(){let e=this.view,t=this.palette;!e||!t||(e.setBackgroundColor(t.background),e.setTextColor(t.foreground),e.setHighlightColor(t.selectionBackground),e.invalidate())}applySelection(){let e=this.view;if(!e)return;let t=e.getText().length(),n=Math.min(this.selection.start,t);e.getSelectionStart()===n&&e.getSelectionEnd()===Math.min(this.selection.end,t)||e.setSelection(n,Math.min(this.selection.end,t))}flushEdits(){let e=this.view,t=this.host;if(this.applying||!e||!t||this.queue.length===0)return;let n=this.queue;this.queue=[];for(let e of n)t.onNativeEdit(e.start,e.removed,e.inserted);t.onNativeSelection(e.getSelectionStart(),e.getSelectionEnd())}selectionChanged(e,t){this.applying||this.queue.length>0||(this.selection={start:e,end:t},this.host?.onNativeSelection(e,t),this.view?.invalidate())}invalidateGutter(){let e=this.view;e&&(this.gutterPixels(e)===this.appliedGutter?e.invalidate():this.applyLayout())}fill(e,t,n,r,i,a){this.fillPaint??=new android.graphics.Paint(0),this.fillPaint.setColor(t),e.drawRect(n,r,i,a,this.fillPaint)}drawBehind(e,t){let n=this.palette,r=e.getLayout();if(!n||!r||!this.layout?.highlightCurrentLine||n.currentLineBackground===0)return;let i=r.getLineForOffset(e.getSelectionEnd()),a=e.getExtendedPaddingTop();this.fill(t,n.currentLineBackground,e.getScrollX(),a+r.getLineTop(i),e.getScrollX()+e.getWidth(),a+r.getLineBottom(i))}drawGutter(e,t){let r=this.palette,a=e.getLayout(),o=this.host;if(!r||!a||!o)return;let s=this.layout?.showLineNumbers===!0,c=this.density(e),l=e.getScrollY(),u=e.getExtendedPaddingTop(),d=i(a.getLineCount(),e=>u+a.getLineTop(e),e=>u+a.getLineBottom(e),l,l+e.getHeight()),f=d?o.queryGutter(d.first,d.last):o.gutterColumns().map(e=>({...e,cells:[]}));if(!s&&f.length===0)return;let p=this.paintFor(e);f.forEach((e,t)=>{let n=e.cells.reduce((e,t)=>Math.max(e,p.measureText(t.text)),0);this.measured[t]=Math.max(n,this.measured[t]??0)}),this.measured.length=f.length;let m=this.gutterPixels(e,a.getLineCount());m!==this.appliedGutter&&(this.appliedGutter=m,e.post(new java.lang.Runnable({run:()=>this.applyLayout()})));let h=e.getScrollX();if(this.fill(t,r.lineNumberBackground,h,l,h+m,l+e.getHeight()),!d)return;let g=8*c,_=n(this.layout?.highlightCurrentLine===!0,a.getLineForOffset(e.getSelectionEnd())),v=h,drawNumbers=()=>{let n=this.numbersPixels(e,a.getLineCount());p.setTextAlign(android.graphics.Paint.Align.RIGHT);for(let e=d.first;e<=d.last;e++){let i=e===_;i&&r.currentLineNumberBackground!==0&&this.fill(t,r.currentLineNumberBackground,v,u+a.getLineTop(e),v+n,u+a.getLineBottom(e)),p.setColor(i?r.currentLineNumberForeground:r.lineNumberForeground),t.drawText(String(e+1),v+n-g,u+a.getLineBaseline(e),p)}v+=n},y=!s;f.forEach((e,n)=>{!y&&e.position>=0&&(drawNumbers(),y=!0),p.setTextAlign(android.graphics.Paint.Align.LEFT),p.setColor(r.lineNumberForeground),e.cells.forEach((n,r)=>{if(n.text===``)return;let i=u+a.getLineBaseline(d.first+r);t.drawText(n.text,v+e.marginStart*c,i,p)}),v+=this.columnPixels(e,this.measured[n],c)}),y||drawNumbers()}};function createEditorDriver(){return new AndroidEditorDriver}export{createEditorDriver};
|
|
@@ -1 +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};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import"./font-size.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;fontSize;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()}setFontSize(e){this.fontSize=e,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=this.fontSize??e.font?.pointSize??14.67;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};
|
package/lib/esm/native-editor.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";var UnsupportedEditorDriver=class{gutterSides=[3,4];bind(e){}createNativeView(){throw Error(`Platform not supported: GtkSource.View is implemented for Android only`)}attach(){}detach(){}setText(){}replaceRange(){}setSelection(){}setLineCount(){}setLayout(){}invalidateGutter(){}spliceLines(){}paintLine(){}clearAll(){}setPalette(){}};function createEditorDriver(){return new UnsupportedEditorDriver}export{createEditorDriver};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";var UnsupportedEditorDriver=class{gutterSides=[3,4];bind(e){}createNativeView(){throw Error(`Platform not supported: GtkSource.View is implemented for Android only`)}attach(){}detach(){}setFontSize(){}setText(){}replaceRange(){}setSelection(){}setLineCount(){}setLayout(){}invalidateGutter(){}spliceLines(){}paintLine(){}clearAll(){}setPalette(){}};function createEditorDriver(){return new UnsupportedEditorDriver}export{createEditorDriver};
|
package/lib/esm/view.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import"./_virtual/_rolldown/runtime.js";import{createEditorDriver as e}from"./native-editor.js";import{EditorSession as t,GtkSourceBuffer as n,GutterSet as r,STOP_EMISSION as i,toBoolean as a,toNumber as o}from"@gjsify/gtksource-core";import{View as s}from"@nativescript/core";import{adwaitaColorScheme as c,onAdwaitaColorSchemeChanged as l,withGtkWidgetLayout as u}from"@gjsify/adwaita-nativescript";import{Adjustment as d}from"@gjsify/adwaita-nativescript/gtk";var GtkSourceView=class extends u(s){static GTypeName=`GtkSourceView`;static builderSlots=[`buffer`];driver=e();session;unsubscribe=null;vadj=new d;hadj=new d;_direction=1;gutters=new r(this);constructor(){super(),this.className=`gtksource-view`,this.session=new t(this.driver,void 0,c()),this.session.bindGutters(this.gutters)}createNativeView(){return this.driver.createNativeView(this._context)}initNativeView(){super.initNativeView(),this.driver.attach(this.nativeViewProtected),this.unsubscribe=l(()=>this.session.setColorScheme(c())),this.session.setColorScheme(c())}disposeNativeView(){this.unsubscribe?.(),this.unsubscribe=null,this.driver.detach(),super.disposeNativeView()}_addChildFromBuilder(e,t){if(e!==`buffer`||!(t instanceof n))throw Error(`GtkSource.View takes only a \`buffer\` object child, not '${e}'.`);this.buffer=t}get buffer(){return this.session.buffer}set buffer(e){this.session.buffer=e}get autoIndent(){return this.session.autoIndent}set autoIndent(e){this.session.autoIndent=a(e,`GtkSource.View.autoIndent`)}get indentWidth(){return this.session.indentWidth}set indentWidth(e){this.session.indentWidth=o(e,`GtkSource.View.indentWidth`)}get showLineNumbers(){return this.session.showLineNumbers}set showLineNumbers(e){this.session.showLineNumbers=a(e,`GtkSource.View.showLineNumbers`)}get highlightCurrentLine(){return this.session.highlightCurrentLine}set highlightCurrentLine(e){this.session.highlightCurrentLine=a(e,`GtkSource.View.highlightCurrentLine`)}get monospace(){return this.session.monospace}set monospace(e){this.session.monospace=a(e,`GtkSource.View.monospace`)}get editable(){return this.session.editable}set editable(e){this.session.editable=a(e,`GtkSource.View.editable`)}get cursorVisible(){return this.session.cursorVisible}set cursorVisible(e){this.session.cursorVisible=a(e,`GtkSource.View.cursorVisible`)}get cursor_visible(){return this.cursorVisible}set cursor_visible(e){this.cursorVisible=e}get_cursor_visible(){return this.cursorVisible}set_cursor_visible(e){this.cursorVisible=e}get_editable(){return this.editable}set_editable(e){this.editable=e}get highlight_current_line(){return this.highlightCurrentLine}set highlight_current_line(e){this.highlightCurrentLine=e}get show_line_numbers(){return this.showLineNumbers}set show_line_numbers(e){this.showLineNumbers=e}get vadjustment(){return this.vadj}get hadjustment(){return this.hadj}get_vadjustment(){return this.vadj}get_hadjustment(){return this.hadj}set_direction(e){if(![0,1,2].includes(e))throw TypeError(`${e} is not a valid value for enum argument dir`);this._direction=e}get_direction(){return this._direction}get_gutter(e){return this.gutters.get(e)}get leftMargin(){return this.session.leftMargin}set leftMargin(e){this.session.leftMargin=o(e,`GtkSource.View.leftMargin`)}get rightMargin(){return this.session.rightMargin}set rightMargin(e){this.session.rightMargin=o(e,`GtkSource.View.rightMargin`)}get topMargin(){return this.session.topMargin}set topMargin(e){this.session.topMargin=o(e,`GtkSource.View.topMargin`)}get bottomMargin(){return this.session.bottomMargin}set bottomMargin(e){this.session.bottomMargin=o(e,`GtkSource.View.bottomMargin`)}connect(e,t){return this.session.connect(e,((e,...n)=>t(this,...n)))}connect_after(e,t){return this.session.connect_after(e,((e,...n)=>t(this,...n)))}[i](e){this.session[i](e)}disconnect(e){this.session.disconnect(e)}};export{GtkSourceView};
|
|
1
|
+
import"./_virtual/_rolldown/runtime.js";import{createEditorDriver as e}from"./native-editor.js";import{EditorSession as t,GtkSourceBuffer as n,GutterSet as r,STOP_EMISSION as i,toBoolean as a,toNumber as o}from"@gjsify/gtksource-core";import{View as s}from"@nativescript/core";import{adwaitaColorScheme as c,onAdwaitaColorSchemeChanged as l,withGtkWidgetLayout as u}from"@gjsify/adwaita-nativescript";import{Adjustment as d}from"@gjsify/adwaita-nativescript/gtk";var GtkSourceView=class extends u(s){static GTypeName=`GtkSourceView`;static builderSlots=[`buffer`];driver=e();session;unsubscribe=null;vadj=new d;hadj=new d;_direction=1;gutters=new r(this);onFontSizeChange=()=>this.driver.setFontSize(this.style.fontSize);constructor(){super(),this.className=`gtksource-view`,this.session=new t(this.driver,void 0,c()),this.session.bindGutters(this.gutters)}createNativeView(){return this.driver.createNativeView(this._context)}initNativeView(){super.initNativeView(),this.driver.setFontSize(this.style.fontSize),this.driver.attach(this.nativeViewProtected),this.style.addEventListener(`fontSizeChange`,this.onFontSizeChange),this.unsubscribe=l(()=>this.session.setColorScheme(c())),this.session.setColorScheme(c())}disposeNativeView(){this.unsubscribe?.(),this.unsubscribe=null,this.style.removeEventListener(`fontSizeChange`,this.onFontSizeChange),this.driver.detach(),super.disposeNativeView()}_addChildFromBuilder(e,t){if(e!==`buffer`||!(t instanceof n))throw Error(`GtkSource.View takes only a \`buffer\` object child, not '${e}'.`);this.buffer=t}get buffer(){return this.session.buffer}set buffer(e){this.session.buffer=e}get autoIndent(){return this.session.autoIndent}set autoIndent(e){this.session.autoIndent=a(e,`GtkSource.View.autoIndent`)}get indentWidth(){return this.session.indentWidth}set indentWidth(e){this.session.indentWidth=o(e,`GtkSource.View.indentWidth`)}get showLineNumbers(){return this.session.showLineNumbers}set showLineNumbers(e){this.session.showLineNumbers=a(e,`GtkSource.View.showLineNumbers`)}get highlightCurrentLine(){return this.session.highlightCurrentLine}set highlightCurrentLine(e){this.session.highlightCurrentLine=a(e,`GtkSource.View.highlightCurrentLine`)}get monospace(){return this.session.monospace}set monospace(e){this.session.monospace=a(e,`GtkSource.View.monospace`)}get editable(){return this.session.editable}set editable(e){this.session.editable=a(e,`GtkSource.View.editable`)}get cursorVisible(){return this.session.cursorVisible}set cursorVisible(e){this.session.cursorVisible=a(e,`GtkSource.View.cursorVisible`)}get cursor_visible(){return this.cursorVisible}set cursor_visible(e){this.cursorVisible=e}get_cursor_visible(){return this.cursorVisible}set_cursor_visible(e){this.cursorVisible=e}get_editable(){return this.editable}set_editable(e){this.editable=e}get highlight_current_line(){return this.highlightCurrentLine}set highlight_current_line(e){this.highlightCurrentLine=e}get show_line_numbers(){return this.showLineNumbers}set show_line_numbers(e){this.showLineNumbers=e}get vadjustment(){return this.vadj}get hadjustment(){return this.hadj}get_vadjustment(){return this.vadj}get_hadjustment(){return this.hadj}set_direction(e){if(![0,1,2].includes(e))throw TypeError(`${e} is not a valid value for enum argument dir`);this._direction=e}get_direction(){return this._direction}get_gutter(e){return this.gutters.get(e)}get leftMargin(){return this.session.leftMargin}set leftMargin(e){this.session.leftMargin=o(e,`GtkSource.View.leftMargin`)}get rightMargin(){return this.session.rightMargin}set rightMargin(e){this.session.rightMargin=o(e,`GtkSource.View.rightMargin`)}get topMargin(){return this.session.topMargin}set topMargin(e){this.session.topMargin=o(e,`GtkSource.View.topMargin`)}get bottomMargin(){return this.session.bottomMargin}set bottomMargin(e){this.session.bottomMargin=o(e,`GtkSource.View.bottomMargin`)}connect(e,t){return this.session.connect(e,((e,...n)=>t(this,...n)))}connect_after(e,t){return this.session.connect_after(e,((e,...n)=>t(this,...n)))}[i](e){this.session[i](e)}disconnect(e){this.session.disconnect(e)}};export{GtkSourceView};
|
|
@@ -41,6 +41,7 @@ export interface AndroidEditText {
|
|
|
41
41
|
getSelectionEnd(): number;
|
|
42
42
|
getExtendedPaddingTop(): number;
|
|
43
43
|
getTextSize(): number;
|
|
44
|
+
setTextSize(unit: number, size: number): void;
|
|
44
45
|
getTypeface(): unknown;
|
|
45
46
|
getResources(): {
|
|
46
47
|
getDisplayMetrics(): {
|
|
@@ -109,6 +110,11 @@ export interface AndroidNamespace {
|
|
|
109
110
|
StrikethroughSpan: new () => unknown;
|
|
110
111
|
};
|
|
111
112
|
};
|
|
113
|
+
util: {
|
|
114
|
+
TypedValue: {
|
|
115
|
+
COMPLEX_UNIT_SP: number;
|
|
116
|
+
};
|
|
117
|
+
};
|
|
112
118
|
view: {
|
|
113
119
|
Gravity: {
|
|
114
120
|
TOP: number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const DEFAULT_FONT_SIZE = 14.67;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const NativeEditorAndroidTest: () => Promise<void>;
|
|
@@ -5,5 +5,7 @@ export interface NativeEditorDriver extends EditorDriver {
|
|
|
5
5
|
/** The view `createNativeView()` returned is live: apply everything remembered so far. */
|
|
6
6
|
attach(nativeView: unknown): void;
|
|
7
7
|
detach(): void;
|
|
8
|
+
/** The CSS `font-size` the view resolved, `undefined` while none is set: `DEFAULT_FONT_SIZE` then applies. */
|
|
9
|
+
setFontSize(size: number | undefined): void;
|
|
8
10
|
}
|
|
9
11
|
export declare function createEditorDriver(): NativeEditorDriver;
|
package/lib/types/view.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/gtksource-nativescript",
|
|
3
|
-
"version": "0.64.33
|
|
3
|
+
"version": "0.64.33",
|
|
4
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",
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"editor"
|
|
52
52
|
],
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@gjsify/adwaita-nativescript": "0.64.33
|
|
55
|
-
"@gjsify/gtksource-core": "0.64.33
|
|
54
|
+
"@gjsify/adwaita-nativescript": "^0.64.33",
|
|
55
|
+
"@gjsify/gtksource-core": "^0.64.33"
|
|
56
56
|
},
|
|
57
57
|
"peerDependencies": {
|
|
58
58
|
"@nativescript/core": "*"
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@gjsify/cli": "0.64.33
|
|
67
|
-
"@gjsify/unit": "0.64.33
|
|
66
|
+
"@gjsify/cli": "^0.64.33",
|
|
67
|
+
"@gjsify/unit": "^0.64.33",
|
|
68
68
|
"@types/node": "^25.9.2",
|
|
69
69
|
"typescript": "^6.0.3"
|
|
70
70
|
},
|
|
@@ -90,6 +90,5 @@
|
|
|
90
90
|
"bugs": {
|
|
91
91
|
"url": "https://github.com/gjsify/gjsify/issues"
|
|
92
92
|
},
|
|
93
|
-
"homepage": "https://github.com/gjsify/gjsify/tree/main/packages/nativescript-bridge/gtksource#readme"
|
|
94
|
-
"gitHead": "603d30dc7b5600376fca2b715ecc154cc12b4b31"
|
|
93
|
+
"homepage": "https://github.com/gjsify/gjsify/tree/main/packages/nativescript-bridge/gtksource#readme"
|
|
95
94
|
}
|