Add indent/dedent to python editor in scripter
ClosedPublic

Authored by brendanbd on Dec 20 2017, 6:01 AM.

Details

Summary

Add indent/dedent functionality to editor that ships with scripter script.
Previously tab key added 4 spaces whereever the cursor was. With this commit tab indents selected lines by 2 characters and shift-tab dedents by a the same amount. Empty lines are not indented and dedenting stops once code has reached left hand margin.
2 chars is hard coded but could be a setting later. Chose 2 chars because default editor window is relatively narrow

Test Plan

Run scripter
load or type a multiline script
move cursor to a line, press tab/shift-tab.
select 2 or more lines press tab/shift tab.
select empty lines or lines with only whitespace and press tab/shift-tab

In each case:

Confirm shift tab stops dedenting at left hand margin for each line independently
Confirm tab does not add indents to whitespace-only lines.

Move cursor to middle of text - no selection, press tab - line should indent, no whitespace should be inserted in middle of text
move cursor to end of line, press return press tab - should add whitespace to start typing indented code

Diff Detail

Repository
R37 Krita
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
brendanbd requested review of this revision.Dec 20 2017, 6:01 AM
brendanbd created this revision.

I have added tab/shift tab functionality for the python-editor in scripter.
Not sure whether I am supposed to also open an issue in the bug tracker.
I am thinking of other ui improvements to the editor that may affect this file. Am not sure what I'm supposed to do to handle this conflict if it arises. What do I diff against?

Actually, this has a UI issue for when there is no selection. Will update.

brendanbd updated this revision to Diff 24142.Dec 20 2017, 8:15 AM

Additional changes to allow case:
press return, tab to indent, start code

Previous wouldn't indent to avoid unecessary whitespace padding in selections.
incremental diff because git diff HEAD doesn't seem to be working for me

brendanbd edited the test plan for this revision. (Show Details)Dec 20 2017, 11:53 AM
brendanbd updated this revision to Diff 24161.Dec 20 2017, 12:00 PM
brendanbd added a project: Krita.
brendanbd added a subscriber: Krita.

Previous patch introduced bug - pressing tab in the middle of text when there is no selection inserted whitespace in the middle of the code.
This checks that the cursor is at the end of the text block before inserting spaces

Note: This is an incremental diff. Also, the diff is marked up as against https://phabricator.kde.org/D9430 not as against the previous patch.

Restricted Application added a subscriber: woltherav. · View Herald TranscriptDec 20 2017, 12:00 PM

That's really cool! I'm really happy that someone is workink on this code. There's a lot a things to do and time it's running out on my researching project. Keep going :)

This revision was not accepted when it landed; it landed in state Needs Review.Jan 26 2018, 5:21 AM
Closed by commit R37:944047983146: Add indent/dedent to python editor in scripter (authored by Brendan Bd <bunf2014@apps.opensourcelaw.biz>). · Explain Why
This revision was automatically updated to reflect the committed changes.