Conversation
There was a problem hiding this comment.
Naming nit: I think this would be clearer as something like getCharIndexForColumn(). I know the symmetrical function is named getColOffset(), which isn't very descriptive, but I think getPosOffset() is somewhat less descriptive since it's not really obvious that it has to do with columns or character indices.
There was a problem hiding this comment.
Also...I wonder if there's some clever way to share code with getColOffset(), since the logic is very similar - the only difference is whether you're returning the char index or the column index, and the loop end condition. (It's slightly obscured by the fact that getColOffset() just gets the portion of the line up to the char index, but you could rewrite it to just get the whole line, and just use a different end condition for the two cases.) That said, it's a fairly small amount of code so it's probably not important to be that clever...
There was a problem hiding this comment.
The input is also different. One goes from pos to colOffset and the other goes from colOffset to pos. These functions are opposites, so I don't think complexity added by merging them is worth the few lines of code that are saved.
There was a problem hiding this comment.
We might be able to have a third function with the for, which would receive the line/range and a stop function (which receives the index and the line length and returns true or false) and returns the column. Each function can then call the third one with the line and the stop function.
|
@redmunds Review complete - just a couple of nits. It would also be good to have a couple of unit tests for this...would you mind adding some? |
|
Pushed changes. Ready for another review. |
|
Looks good, merging. Ran grunt test manually since the cla check is erroneously failing in travis. |
For add new selection, use display column
This is for #7286.
Are there are any other commands that need this same behavior?
/cc @njx