lexgui 0.6.6 → 0.6.8

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.
@@ -221,8 +221,9 @@ class CodeEditor {
221
221
 
222
222
  static __instances = [];
223
223
 
224
- static CURSOR_LEFT = 1;
225
- static CURSOR_TOP = 2;
224
+ static CURSOR_LEFT = 1;
225
+ static CURSOR_TOP = 2;
226
+ static CURSOR_LEFT_TOP = CodeEditor.CURSOR_LEFT | CodeEditor.CURSOR_TOP;
226
227
 
227
228
  static SELECTION_X = 1;
228
229
  static SELECTION_Y = 2
@@ -265,8 +266,6 @@ class CodeEditor {
265
266
 
266
267
  panel.addTitle( "EXPLORER" );
267
268
 
268
- this._tabStorage = {};
269
-
270
269
  let sceneData = {
271
270
  'id': 'WORKSPACE',
272
271
  'skipVisibility': true,
@@ -320,6 +319,7 @@ class CodeEditor {
320
319
  this.skipInfo = options.skipInfo ?? false;
321
320
  this.disableEdition = options.disableEdition ?? false;
322
321
 
322
+ this._tabStorage = {};
323
323
  this.tabs = this.area.addTabs( { onclose: (name) => {
324
324
  delete this.openedTabs[ name ];
325
325
  if( Object.keys( this.openedTabs ).length < 2 )
@@ -756,31 +756,43 @@ class CodeEditor {
756
756
  let idx = firstNonspaceIndex( this.code.lines[ ln ] );
757
757
 
758
758
  // We already are in the first non space index...
759
- if(idx == cursor.position) idx = 0;
759
+ if( idx == cursor.position ) idx = 0;
760
760
 
761
761
  const prestring = this.code.lines[ ln ].substring( 0, idx );
762
762
  let lastX = cursor.position;
763
763
 
764
764
  this.resetCursorPos( CodeEditor.CURSOR_LEFT, cursor );
765
- if(idx > 0)
765
+ if( idx > 0 )
766
+ {
766
767
  this.cursorToString( cursor, prestring );
767
- this.setScrollLeft( 0 );
768
+ }
769
+ else
770
+ {
771
+ // No spaces, start from char 0
772
+ idx = 0;
773
+ }
768
774
 
769
- // Merge cursors
775
+ this.setScrollLeft( 0 );
770
776
  this.mergeCursors( ln );
771
777
 
772
778
  if( e.shiftKey && !e.cancelShift )
773
779
  {
774
780
  // Get last selection range
775
781
  if( cursor.selection )
782
+ {
776
783
  lastX += cursor.selection.chars;
784
+ }
777
785
 
778
786
  if( !cursor.selection )
787
+ {
779
788
  this.startSelection( cursor );
789
+ }
780
790
 
781
791
  var string = this.code.lines[ ln ].substring( idx, lastX );
782
792
  if( cursor.selection.sameLine() )
793
+ {
783
794
  cursor.selection.selectInline( cursor, idx, cursor.line, this.measureString( string ) );
795
+ }
784
796
  else
785
797
  {
786
798
  this._processSelection( cursor, e );
@@ -976,7 +988,7 @@ class CodeEditor {
976
988
  }
977
989
  else {
978
990
  cursor.selection.invertIfNecessary();
979
- this.resetCursorPos( CodeEditor.CURSOR_LEFT | CodeEditor.CURSOR_TOP, cursor );
991
+ this.resetCursorPos( CodeEditor.CURSOR_LEFT_TOP, cursor );
980
992
  this.cursorToLine( cursor, cursor.selection.fromY, true );
981
993
  this.cursorToPosition( cursor, cursor.selection.fromX );
982
994
  this.endSelection();
@@ -1057,7 +1069,7 @@ class CodeEditor {
1057
1069
  else
1058
1070
  {
1059
1071
  cursor.selection.invertIfNecessary();
1060
- this.resetCursorPos( CodeEditor.CURSOR_LEFT | CodeEditor.CURSOR_TOP, cursor );
1072
+ this.resetCursorPos( CodeEditor.CURSOR_LEFT_TOP, cursor );
1061
1073
  this.cursorToLine( cursor, cursor.selection.toY );
1062
1074
  this.cursorToPosition( cursor, cursor.selection.toX );
1063
1075
  this.endSelection();
@@ -1090,7 +1102,7 @@ class CodeEditor {
1090
1102
  this.addTab("+", false, "New File");
1091
1103
  }
1092
1104
 
1093
- this.addTab( options.name || "untitled", true, options.title, { language: "Plain Text" } );
1105
+ this.addTab( options.name || "untitled", true, options.title, { language: options.highlight ?? "Plain Text" } );
1094
1106
 
1095
1107
  // Create inspector panel
1096
1108
  let panel = this._createPanelInfo();
@@ -1666,14 +1678,16 @@ class CodeEditor {
1666
1678
  }
1667
1679
 
1668
1680
  this._removeSecondaryCursors();
1669
- var cursor = this._getCurrentCursor( true );
1670
1681
 
1682
+ var cursor = this._getCurrentCursor( true );
1671
1683
  this.saveCursor( cursor, this.code.cursorState );
1672
-
1673
1684
  this.code = this.loadedTabs[ name ];
1674
1685
  this.restoreCursor( cursor, this.code.cursorState );
1675
1686
 
1676
1687
  this.endSelection();
1688
+
1689
+ this.hideAutoCompleteBox();
1690
+
1677
1691
  this._updateDataInfoPanel( "@tab-name", name );
1678
1692
 
1679
1693
  if( this.code.languageOverride )
@@ -1771,7 +1785,7 @@ class CodeEditor {
1771
1785
  if( selected )
1772
1786
  {
1773
1787
  this.code = code;
1774
- this.resetCursorPos( CodeEditor.CURSOR_LEFT | CodeEditor.CURSOR_TOP );
1788
+ this.resetCursorPos( CodeEditor.CURSOR_LEFT_TOP );
1775
1789
  this.processLines();
1776
1790
  }
1777
1791
 
@@ -1845,10 +1859,26 @@ class CodeEditor {
1845
1859
 
1846
1860
  // Select as current...
1847
1861
  this.code = code;
1848
- this.resetCursorPos( CodeEditor.CURSOR_LEFT | CodeEditor.CURSOR_TOP );
1862
+ this.resetCursorPos( CodeEditor.CURSOR_LEFT_TOP );
1849
1863
  this.processLines();
1850
1864
  this._changeLanguageFromExtension( LX.getExtension( name ) );
1851
- this._updateDataInfoPanel( "@tab-name", code.tabname );
1865
+ this._updateDataInfoPanel( "@tab-name", code.tabName );
1866
+ }
1867
+
1868
+ closeTab( name, eraseAll ) {
1869
+
1870
+ this.tabs.delete( name );
1871
+
1872
+ if( eraseAll )
1873
+ {
1874
+ delete this.openedTabs[ name ];
1875
+ delete this.loadedTabs[ name ];
1876
+ delete this._tabStorage[ name ];
1877
+ }
1878
+ }
1879
+
1880
+ getSelectedTabName() {
1881
+ return this.tabs.selected;
1852
1882
  }
1853
1883
 
1854
1884
  loadTabFromFile() {
@@ -2204,6 +2234,14 @@ class CodeEditor {
2204
2234
  return;
2205
2235
 
2206
2236
  const key = e.key ?? e.detail.key;
2237
+
2238
+ // Do not propagate "space to scroll" event
2239
+ if( key == ' ' )
2240
+ {
2241
+ e.preventDefault();
2242
+ e.stopPropagation();
2243
+ }
2244
+
2207
2245
  const target = e.detail.targetCursor;
2208
2246
 
2209
2247
  // Global keys
@@ -2343,7 +2381,9 @@ class CodeEditor {
2343
2381
 
2344
2382
  // keys with length > 1 are probably special keys
2345
2383
  if( key.length > 1 && this.specialKeys.indexOf( key ) == -1 )
2384
+ {
2346
2385
  return;
2386
+ }
2347
2387
 
2348
2388
  let lidx = cursor.line;
2349
2389
  this.code.lines[ lidx ] = this.code.lines[ lidx ] ?? "";
@@ -2529,11 +2569,11 @@ class CodeEditor {
2529
2569
 
2530
2570
  async _copyContent( cursor ) {
2531
2571
 
2532
- let text_to_copy = "";
2572
+ let textToCopy = "";
2533
2573
 
2534
2574
  if( !cursor.selection )
2535
2575
  {
2536
- text_to_copy = "\n" + this.code.lines[ cursor.line ];
2576
+ textToCopy = "\n" + this.code.lines[ cursor.line ];
2537
2577
  }
2538
2578
  else
2539
2579
  {
@@ -2553,27 +2593,30 @@ class CodeEditor {
2553
2593
  const num_chars = cursor.selection.chars + ( cursor.selection.toY - cursor.selection.fromY ) * separator.length;
2554
2594
  const text = code.substr( index, num_chars );
2555
2595
  const lines = text.split( separator );
2556
- text_to_copy = lines.join('\n');
2596
+ textToCopy = lines.join('\n');
2557
2597
  }
2558
2598
 
2559
- navigator.clipboard.writeText( text_to_copy ).then(() => console.log("Successfully copied"), (err) => console.error("Error"));
2599
+ navigator.clipboard.writeText( textToCopy );
2600
+ // .then(() => console.log("Successfully copied"), (err) => console.error("Error"));
2560
2601
  }
2561
2602
 
2562
2603
  async _cutContent( cursor ) {
2563
2604
 
2564
2605
  let lidx = cursor.line;
2565
- let text_to_cut = "";
2606
+ let textToCut = "";
2566
2607
 
2567
2608
  this._addUndoStep( cursor, true );
2568
2609
 
2569
2610
  if( !cursor.selection )
2570
2611
  {
2571
- text_to_cut = "\n" + this.code.lines[ cursor.line ];
2612
+ textToCut = "\n" + this.code.lines[ cursor.line ];
2572
2613
  this.code.lines.splice( lidx, 1 );
2573
2614
  this.processLines();
2574
2615
  this.resetCursorPos( CodeEditor.CURSOR_LEFT, cursor );
2575
2616
  if( this.code.lines[ lidx ] == undefined )
2617
+ {
2576
2618
  this.lineUp( cursor );
2619
+ }
2577
2620
  }
2578
2621
  else
2579
2622
  {
@@ -2581,24 +2624,27 @@ class CodeEditor {
2581
2624
  if( cursor.selection ) cursor.selection.invertIfNecessary();
2582
2625
 
2583
2626
  const separator = "_NEWLINE_";
2584
- let code = this.code.lines.join(separator);
2627
+ let code = this.code.lines.join( separator );
2585
2628
 
2586
2629
  // Get linear start index
2587
2630
  let index = 0;
2588
2631
 
2589
- for(let i = 0; i <= cursor.selection.fromY; i++)
2632
+ for( let i = 0; i <= cursor.selection.fromY; i++ )
2633
+ {
2590
2634
  index += (i == cursor.selection.fromY ? cursor.selection.fromX : this.code.lines[ i ].length);
2635
+ }
2591
2636
 
2592
2637
  index += cursor.selection.fromY * separator.length;
2593
- const num_chars = cursor.selection.chars + (cursor.selection.toY - cursor.selection.fromY) * separator.length;
2594
- const text = code.substr(index, num_chars);
2595
- const lines = text.split(separator);
2596
- text_to_cut = lines.join('\n');
2638
+ const numChars = cursor.selection.chars + (cursor.selection.toY - cursor.selection.fromY) * separator.length;
2639
+ const text = code.substr( index, numChars );
2640
+ const lines = text.split( separator );
2641
+ textToCut = lines.join('\n');
2597
2642
 
2598
2643
  this.deleteSelection( cursor );
2599
2644
  }
2600
2645
 
2601
- navigator.clipboard.writeText( text_to_cut ).then(() => console.log("Successfully cut"), (err) => console.error("Error"));
2646
+ navigator.clipboard.writeText( textToCut );
2647
+ // .then(() => console.log("Successfully cut"), (err) => console.error("Error"));
2602
2648
  }
2603
2649
 
2604
2650
  _duplicateLine( lidx, cursor ) {
@@ -3491,7 +3537,7 @@ class CodeEditor {
3491
3537
  this._removeSecondaryCursors();
3492
3538
 
3493
3539
  var cursor = this._getCurrentCursor();
3494
- this.resetCursorPos( CodeEditor.CURSOR_LEFT | CodeEditor.CURSOR_TOP, cursor );
3540
+ this.resetCursorPos( CodeEditor.CURSOR_LEFT_TOP, cursor );
3495
3541
 
3496
3542
  this.startSelection( cursor );
3497
3543
 
@@ -190,12 +190,14 @@ function MAKE_CODE( text, language = "js" )
190
190
 
191
191
  window.MAKE_CODE = MAKE_CODE;
192
192
 
193
- function MAKE_BULLET_LIST( list )
193
+ function MAKE_LIST( list, type )
194
194
  {
195
- console.assert(list && list.length > 0);
196
- let ul = document.createElement('ul');
195
+ const validTypes = [ 'bullet', 'numbered' ];
196
+ console.assert( list && list.length > 0 && validTypes.includes(type), "Invalid list type or empty list" + type );
197
+ const typeString = type == 'bullet' ? 'ul' : 'ol';
198
+ let ul = document.createElement( typeString );
197
199
  for( var el of list ) {
198
- let li = document.createElement('li');
200
+ let li = document.createElement( 'li' );
199
201
  li.className = "leading-loose";
200
202
  li.innerHTML = el;
201
203
  ul.appendChild( li );
@@ -203,8 +205,20 @@ function MAKE_BULLET_LIST( list )
203
205
  mainContainer.appendChild( ul );
204
206
  }
205
207
 
208
+ function MAKE_BULLET_LIST( list )
209
+ {
210
+ MAKE_LIST( list, 'bullet' );
211
+ }
212
+
206
213
  window.MAKE_BULLET_LIST = MAKE_BULLET_LIST;
207
214
 
215
+ function MAKE_NUMBERED_LIST( list )
216
+ {
217
+ MAKE_LIST( list, 'numbered' );
218
+ }
219
+
220
+ window.MAKE_NUMBERED_LIST = MAKE_NUMBERED_LIST;
221
+
208
222
  function ADD_CODE_LIST_ITEM( item, target )
209
223
  {
210
224
  target = target ?? window.listQueued;
@@ -388,25 +402,19 @@ function INSERT_VIDEO( src, caption = "", controls = true, autoplay = false )
388
402
 
389
403
  window.INSERT_VIDEO = INSERT_VIDEO;
390
404
 
391
- function MAKE_NOTE( string, title = "Note" )
405
+ function MAKE_NOTE( string, warning, title, icon )
392
406
  {
393
407
  console.assert( string );
394
408
 
395
- let note = document.createElement( 'div' );
396
- note.className = "note";
409
+ const note = LX.makeContainer( [], "border rounded-lg overflow-hidden text-md fg-secondary my-6", "", mainContainer );
397
410
 
398
411
  let header = document.createElement( 'div' );
399
- header.className = "note-header";
400
- header.appendChild( LX.makeIcon( "NotepadText" ) );
401
- header.innerHTML += "<b>" + title + "</b>";
402
-
403
- let body = document.createElement( 'div' );
404
- body.className = "note-body";
405
- body.innerHTML = string;
406
-
412
+ header.className = "flex bg-tertiary font-semibold px-3 py-2 gap-2 fg-secondary";
413
+ header.appendChild( LX.makeIcon( icon ?? ( warning ? "MessageSquareWarning" : "NotepadText" ) ) );
414
+ header.innerHTML += ( title ?? ( warning ? "Important" : "Note" ) );
407
415
  note.appendChild( header );
408
- note.appendChild( body );
409
- mainContainer.appendChild( note );
416
+
417
+ const body = LX.makeContainer( [], "leading-6 p-3", string, note );
410
418
  }
411
419
 
412
420
  window.MAKE_NOTE = MAKE_NOTE;
@@ -151,7 +151,7 @@ code.inline.desc {
151
151
  }
152
152
 
153
153
  #content strong {
154
- font-weight:900;
154
+ font-weight:700;
155
155
  }
156
156
 
157
157
  #content a.permalink {
@@ -225,29 +225,6 @@ code.inline.desc {
225
225
 
226
226
  }
227
227
 
228
- #goUpButton {
229
- position: fixed;
230
- z-index: 10;
231
- bottom: 32px;
232
- right: 32px;
233
- border: 1px solid #666;
234
- border-radius: 6px;
235
- outline: none;
236
- background: none;
237
- font-size: 18px;
238
- padding: 6px;
239
- color: #bbb;
240
- transition: all 0.25s;
241
- width: 32px;
242
- height: 32px;
243
- }
244
-
245
- #goUpButton:hover {
246
- color: #ccc;
247
- border-color: #ccc;
248
- cursor: pointer;
249
- }
250
-
251
228
  pre .str, code .str { color: #c79369; } /* string */
252
229
  pre .kwd, code .kwd { color: #2194ce; } /* keyword */
253
230
  pre .com, code .com { color: #999999; } /* comment */
@@ -295,50 +272,17 @@ code:has(.constructor) {
295
272
  }
296
273
 
297
274
  #content span.solid {
298
- /* background-color: var(--global-selected); */
299
275
  border-radius: 8px;
300
276
  padding: 2px;
301
277
  padding-inline: 8px;
302
278
  }
303
279
 
304
280
  #content span.outline {
305
- /* border: 1px solid var(--global-accent); */
306
- /* color: var(--global-selected); */
307
281
  border-radius: 8px;
308
282
  padding: 2px;
309
283
  padding-inline: 8px;
310
284
  }
311
285
 
312
- .note {
313
- border-radius: 8px;
314
- overflow: hidden;
315
- margin: 16px 0;
316
- font-size: 0.95rem;
317
- color: var(--global-text-secondary);
318
- box-shadow: 0 1px 3px var(--global-color-tertiary);
319
- }
320
-
321
- .note-header {
322
- background-color: var(--global-color-tertiary);
323
- color: var(--global-text-secondary);
324
- padding: 8px 12px;
325
- display: flex;
326
- align-items: center;
327
- gap: 0.5em;
328
- font-weight: bold;
329
- }
330
-
331
- .note-header svg {
332
- width: 1em;
333
- height: 1em;
334
- flex-shrink: 0;
335
- }
336
-
337
- .note-body {
338
- padding: 12px;
339
- line-height: 1.5;
340
- }
341
-
342
286
  :root[data-theme="light"] #content {
343
287
  color: #202124;
344
288
  }
package/build/lexgui.css CHANGED
@@ -3835,10 +3835,9 @@ meter:-moz-meter-sub-sub-optimum::-moz-meter-bar {
3835
3835
  .lexwidget:has(.lextogglesubmenu),
3836
3836
  .lexwidget:has(.lexcustomcontainer) {
3837
3837
  border-radius: 6px;
3838
- display: grid;
3839
- grid-template-columns: repeat(2, 1fr);
3840
- grid-template-rows: auto auto;
3841
3838
  transition: background-color 0.2s ease-out;
3839
+ display: flex;
3840
+ flex-wrap: wrap;
3842
3841
  }
3843
3842
 
3844
3843
  .lexwidget:has(.lexarrayitems)[data-opened=true],