hankinsoft / SQLPro

SQLPro bug & features tracking.
100 stars 27 forks source link

Bug with indenting multiple lines. #904

Closed manngo closed 1 year ago

manngo commented 1 year ago

Describe the bug A clear and concise description of what the bug is.

I have a statement as follows:

WITH
    cte2(rn,height) AS (
        SELECT row_number() OVER(ORDER BY height), height
        FROM customers WHERE height IS NOT NULL),
    cte3(mid1,mid2) AS (SELECT floor((count(*)+1)/2),floor((count(*)+2)/2) from cte2)
SELECT avg(height)
FROM cte2,cte3 WHERE rn in (mid1,mid2);

(A heavy-handed way of calculating the median). The statement is not important.

If I select it, I should be able to indent it all with the TAB key. However, sometimes, only the first line is indented. See the attached recording. I have also attached a zipped version of an actual sql document, though I don’t know whether the problem persists.

I believe it has something to do with the line endings. If I copy the text to Pulsar (formerly known as Atom) and view invisibles, I can’t see anything wrong. However, if I then change the line endings to either LF or CRLF and copy it back again it’s OK. It seems to think that each line is a continuation of the previous line.

I have found that using Edit | Format Query fixes it, but it affects the whole question and the output is too over-the-top for my liking.

To Reproduce

I can’t reproduce this reliably.

Screenshots

See attached Recording

Environment (please complete the following information):

Additional context Add any other context about the problem here.

https://github.com/hankinsoft/SQLPro/assets/3796633/cfd950f4-b820-4afb-8227-347d2a34ed54

sample.sql.zip

manngo commented 1 year ago

I’m getting some idea of what’s going on.

I copied the offending text into a hex editor and I see that some of the line breaks are 0D CR instead of 0A LF characters. I wrote a little service to convert 0D0A and 0D into plain 0A and that fixes the problem for me. I think.

I don’t know at this moment what’s going on with the line endings. I do spend a lot of time copying and pasting between applications so something may get warped in translation.

hankinsoft commented 1 year ago

Thanks for all the details - that gives me enough to work work. I'm going to try and try this down and get it sorted out.

hankinsoft commented 1 year ago

Could you try https://sqlprostudio.s3.us-east-1.amazonaws.com/studio/SQLProStudio.2023.41.app.zip and see if it sorts the indention issue?

manngo commented 1 year ago

I think it works.

I had some text which had a problem, copied and pasted the text just below and tried to indent/unindent. The current version persists the problem, while the new version fixes it.

Just out of morbid curiosity, what was happening there?

hankinsoft commented 1 year ago

SQLPro (and macOS in general) expects lines to be \n rather than \r or even \r\n. When you paste into SQLPro now it converts to \n which helps the intending code work properly.

I'm submitting the SQLPro Studio version to the App Store today which generally takes a few days to be approved. I'll post here again once its available.

manngo commented 1 year ago

I have just updated SQLPro but I think there’s a new related issue.

If I paste something, the cursor jumps to the end of the current document. It also forgets the syntax highlighting.

https://github.com/hankinsoft/SQLPro/assets/3796633/6719774f-7d96-4a23-a699-6547a8f7c1e4

It’s a little awkward on long documents. I’m sorry, I didn’t notice this with the test version.

yeysman commented 1 year ago

@hankinsoft Same issue what described above after the last update Version 2023.42 (Build 111042.5): After copy-past - no syntax highlighting and cursor jumps to the end of the line. Could you please fix it or rollback this change (at least for App Store)?

manngo commented 1 year ago

@yeysman Just for the moment I rolled back the update from my Time Machine.

hankinsoft commented 1 year ago

Latest build has been approved and this should be sorted up. Please let me know if this is removed for you.

yeysman commented 1 year ago

@hankinsoft, Thank you! Last update solves issue.

hankinsoft commented 1 year ago

@yeysman awesome, sorry about that.

@manngo can you confirm if this build sorts your paste/format issue?

manngo commented 1 year ago

Brilliant. This fixes it. Thanks as always.

hankinsoft commented 1 year ago

Awesome, thanks for letting me know!