Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Outdent code when running selection from a notebook #1391

Merged
merged 4 commits into from
Jul 6, 2023

Conversation

mattrunyon
Copy link
Collaborator

Fixes #1326

To test, put code in a notebook and run a selection where every line is indented. For example, run the function body of this code

def my_func():
  a = 2
  b = 3
  c = a + b
  print(c)

Could be made into a util if we want to use it elsewhere. I looked in the monaco documentation to see if it had anything built-in for this and couldn't find any methods for it

@mattrunyon mattrunyon requested a review from mofojed June 30, 2023 16:13
@mattrunyon mattrunyon self-assigned this Jun 30, 2023
mofojed
mofojed previously approved these changes Jun 30, 2023
packages/console/src/notebook/ScriptEditor.tsx Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Jun 30, 2023

Codecov Report

Merging #1391 (a3ab2bb) into main (ed3a8c5) will increase coverage by 0.04%.
The diff coverage is 72.72%.

@@            Coverage Diff             @@
##             main    #1391      +/-   ##
==========================================
+ Coverage   45.58%   45.63%   +0.04%     
==========================================
  Files         506      506              
  Lines       34966    34984      +18     
  Branches     8734     8740       +6     
==========================================
+ Hits        15940    15964      +24     
+ Misses      18975    18969       -6     
  Partials       51       51              
Flag Coverage Δ
unit 45.63% <72.72%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/console/src/notebook/ScriptEditor.tsx 0.00% <0.00%> (ø)
packages/console/src/notebook/ScriptEditorUtils.ts 100.00% <100.00%> (+100.00%) ⬆️

... and 16 files with indirect coverage changes

Copy link
Contributor

@dsmmcken dsmmcken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def my_func():
    # run from here
    a = 2
    b = 3

    def nested(x,y):
        return (a + b)

    c = nested(a, b)
    print(c)
    # to here
    return c

Failure case

@mattrunyon
Copy link
Collaborator Author

@dsmmcken Good catch. The newline is what wasn't accounted for (indent size is 0). Maybe I should pull this out into a util and write a few unit tests

@mattrunyon mattrunyon changed the title feat: Un-indent code when running selection from a notebook feat: Outdent code when running selection from a notebook Jun 30, 2023
packages/utils/src/TextUtils.test.ts Outdated Show resolved Hide resolved
packages/utils/src/TextUtils.ts Outdated Show resolved Hide resolved
@mattrunyon mattrunyon requested a review from mofojed July 5, 2023 17:48
@mofojed mofojed dismissed dsmmcken’s stale review July 6, 2023 13:16

Already been addressed

@mattrunyon mattrunyon merged commit 154ccfc into deephaven:main Jul 6, 2023
@mattrunyon mattrunyon deleted the mattrunyon-indent-handling branch July 6, 2023 16:34
@github-actions github-actions bot locked and limited conversation to collaborators Jul 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DevX feedback: IDE could handle indents better
3 participants