Alexey-T / CudaText

Cross-platform text editor, written in Free Pascal
Mozilla Public License 2.0
2.49k stars 170 forks source link

Missing indentation guides #5449

Closed pintassilgo closed 6 months ago

pintassilgo commented 6 months ago

Cuda: image

Sublime: image

VSCode: image

As you can see, Cuda is missing indentation guides for col 1 and also for col 3 when within an array block.

Extra: how to make indentation guides only mark child lines? Compare Cuda with others. In others, lines opening or closing the block aren't marked with indentation guide and it looks better this way, but in Cuda they are marked image image .

Alexey-T commented 6 months ago

we call them 'staples'. so try to play with:

Screenshot from 2024-04-01 19-33-10

missing lines for [] and for column 1 - to fix.

Alexey-T commented 6 months ago

Opt value 0,40,0,0 gives almost what you want! except missing line for [].

pintassilgo commented 6 months ago

Yes, thanks, fixed except by missing line for []. I suggest you to set this as default value, as you can see this is the default for other popular editors.

Alexey-T commented 6 months ago

when I changed the option to 0,40,0,0, Python shows this: not nice.

py

what is ST/VSCode showing?

pintassilgo commented 6 months ago

cuda_hilite py

Sublime: image

VSCode: image

pintassilgo commented 6 months ago

OK, now with the same file as you:

VSCode: image

Sublime: image

So Cuda needs a fix.

Alexey-T commented 6 months ago

Todo.

pintassilgo commented 6 months ago

Seems that the only missing thing here, after changing defaults to 0,40,0,0, is to add +1 bottom line for Python-like languages.

Alexey-T commented 6 months ago

Change made:

Alexey-T commented 6 months ago

Get new beta, and fixed lexer: https://github.com/Alexey-T/CudaText/blob/master/app/data/lexlib/JavaScript.lcf

fol

pintassilgo commented 6 months ago

Thanks. Not entirely fixed yet:

image

test.js ```js let obj = { sites: [ { pr: 1, ac: 2, }, { pr: 1, ac: 3, }, { a: 1, a: 5, } ], onClick (ev) { console.log(ev); }, onkeydown: function () { // ← missing indentation guide here return; } } ```

VSCode is fine: image

Alexey-T commented 6 months ago

fixed, download the JS lex again.

Screenshot from 2024-04-02 17-07-33

pintassilgo commented 6 months ago

By the way, looking at these screenshots, code color scheme of VSCode looks better, using different colors for each hierarchy level of block (root is yellow, level 2 is pink, level 3 is blue; then 4 is yellow again, 5 pink, blue... so 3 different colors).

Other difference is the most of the code in Cuda has no color, while in VSCode objects and arrays are blue, methods/function names are yellow...

Is there any way to achieve similar results in Cuda?

Alexey-T commented 6 months ago

using different colors for each hierarchy level of block (root is yellow, l

Should be made by custom plugin (API ed.attr())

the most of the code in Cuda has no color, while in VSCode objects and arrays are blue

Can be changed by editing JS lexer in lexer editor. but it will make lexer SLOWER.

pintassilgo commented 6 months ago

Thanks. Still some missing staples:

image

VSCode: image

test.js ```js let obj = { sites: [ { pr: 1, ac: 2, }, { pr: 1, ac: 3, }, { a: 1, a: 5, } ], onClick (ev) { console.log(ev); }, onkeydown: function () { // ← missing indentation guide here return; }, init: async function () { let delay = Math.max(0, Date.now() - 1000); lib.initWithCallback( async () => { this.status = 1; for (const [k, v] of this.ids) { let step = await this.scrap(k, v[0], v[1], v[2], v[3]); if (!step) break; await this.sleep(60000); } if (this.status < 2) { this.edit(); } else { this.timer.cancel(); await this.sleep(300000); this.init(); } }, delay ); }, } ```
Alexey-T commented 6 months ago

fixed, redownload lexer.

pintassilgo commented 6 months ago

Fixed one of the missing staples, not the other one: image

pintassilgo commented 6 months ago

Also this one down the if:

image

Alexey-T commented 6 months ago

fixed, redownload lexer.

Also this one down the if:

this must not be fixed, no block brackets {}. sorry.

pintassilgo commented 6 months ago

Thanks.

this must not be fixed, no block brackets {}. sorry.

Do you mean you think it's correct the way it is? Every other editor have the staples.

Sublime: image

Kate: image

Alexey-T commented 6 months ago

Do you mean you think it's correct the way it is? Every other editor have the staples.

cannot do this , maybe even with hard work. that block dont have explicit start + explicit end.

pintassilgo commented 6 months ago

OK, I think it's reasonable. But how about this:

image

VSCode: image

Sublime: image

Kate: image

demo.js ```js let obj = { STYLE: { url: Services.io.newURI('data:text/css;charset=UTF-8,' + encodeURIComponent(` @-moz-document url('${_uc.BROWSERCHROME}'), url('chrome://messenger/content/customizeToolbar.xhtml') { #styloaix-button.icon-white { list-style-image: url('chrome://userchromejs/content/styloaix/16w.png'); } #styloaix-button.icon-colored { list-style-image: url('chrome://userchromejs/content/styloaix/16.png'); } } @-moz-document url('${_uc.BROWSERCHROME}') { .styloaix-usersheet .menu-iconic-accel { color: blue; } .styloaix-agentsheet .menu-iconic-accel { color: green; } } `)), type: _uc.sss.AUTHOR_SHEET }, } ```
Alexey-T commented 6 months ago

this cannot be solved - until someone edits the JS lexer and makes tick-strings (ok name?) parsed by SUBLEXER. then sublexer can add folding. but it is bad - what rules must that sublexer have? JS like? HTML like? SQL like? Rust like? syntax can be any there.

pintassilgo commented 6 months ago

By the way, look how every other editor understand that ${} within a `` string is JS code so it has different color compared to the rest of the string. Can I open an issue asking for such lexer improvements?

Alexey-T commented 6 months ago

By the way, look how every other editor understand that ${} within a `` string is JS code so it has different color compared to the rest of the string. Can I open an issue asking for such lexer improvements?

no please, instead try to use the special plugin here: Highlight Variables. it is special for this case.

pintassilgo commented 6 months ago

this cannot be solved - until someone edits the JS lexer and makes tick-strings (ok name?) parsed by SUBLEXER. then sublexer can add folding. but it is bad - what rules must that sublexer have? JS like? HTML like? SQL like? Rust like? syntax can be any there.

The staples are shown for all the three editors even in a new document without any lexer defined (plain text).

The suggestion is to create staples based on indentation levels, maybe under option (but as I said it's default on every other popular editor).

pintassilgo commented 6 months ago

Plain text Kate: image

Plain text Sublime: image

Plain text VSCode: image

Alexey-T commented 6 months ago

The staples are shown for all the three editors even in a new document without any lexer defined (plain text).

The suggestion is to create staples based on indentation levels, maybe under option (but as I said it's default on almost every other popular editor).

Cud don't have this feature- folding based on indent level W/O LEXER. all folding is from lexers. for text files - we have lexer 'Text with indentation'.

pintassilgo commented 6 months ago

I tried Text with indentation but it only creates folding sections, not staples.

image

When this gets fixed, Text with indentation is probably your answer for this question about what to use within a string:

what rules must that sublexer have? JS like? HTML like? SQL like? Rust like? syntax can be any there.

pintassilgo commented 6 months ago

And how to make Text with indentation default to replace (none)?

Alexey-T commented 6 months ago

Text with indentation is updated in addons - in 3 mins you can see it's updated, it has staples now

Alexey-T commented 6 months ago

And how to make Text with indentation default to replace (none)?

option "newdoc_lexer"?

pintassilgo commented 6 months ago

it has staples now

Thanks.

option "newdoc_lexer"?

Yes, thanks.

Alexey-T commented 6 months ago

When this gets fixed, Text with indentation is probably your answer for this question about what to use within a string: what rules must that sublexer have? JS like? HTML like? SQL like? Rust like? syntax can be any there.

lexer dependancy in JS to 'Text with indentation' will be bad - most ppl won't get the sublexer and won't have idea that such sublexer is supported

pintassilgo commented 6 months ago

Or add Text with indentation logic in JS lexer to work inside template literals (multiline strings in JS). The only specificity it has is that ${} is the way to concatenate code result inside the string. So `Hi, ${name}, how are you?` is the same as "Hi, " + name + ", how are you?". Other than that, the multiline string should be treated as simple text with indentation.

You decide, of course, but I shown that's how other popular editors work.

Alexey-T commented 6 months ago

I don't like the idea to add dependency to 'text with ind' lexer to JS lexer. You can clone the JS lexer and edit it in lexer editor. name it like 'JavaScript_' so it will appear next to usual lexer..