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

Add shortcut to move a line up and down #337

Merged
merged 1 commit into from
Oct 18, 2017

Conversation

xgouchet
Copy link
Member

Pressing Alt+Arrow Up / Alt+Arrow Down will move the current line
up/down. This is a nice feature to move lines without having to do a
Select-Cut-Move-Paste manipulation.

@mitya57
Copy link
Member

mitya57 commented Oct 17, 2017

Maybe implement it as QAction instead? This way you will be able to show it in Edit menu and right-click menu for increased visibility.

@xgouchet
Copy link
Member Author

@mitya57 Done, I also added the actions in the tool bar

Copy link
Member

@mitya57 mitya57 left a comment

Choose a reason for hiding this comment

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

Better, but still not there ;)

ReText/editor.py Outdated
@@ -197,6 +197,9 @@ def contextMenuEvent(self, event):
actions = [self.parent.act(sug, trig=self.fixWord(sug)) for sug in suggestions]
menu = self.createStandardContextMenu()
menu.insertSeparator(menu.actions()[0])
menu.insertAction(menu.actions()[0], self.parent.actionMoveDown)
menu.insertAction(menu.actions()[0], self.parent.actionMoveUp)
menu.insertSeparator(menu.actions()[0])
Copy link
Member

Choose a reason for hiding this comment

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

This method returns if no text is selected, see above. Please move this code before line 188.

I would also use addAction/addSeparator instead of insertAction/insertSeparator.

Copy link
Member Author

Choose a reason for hiding this comment

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

I used insert* instead of add* to match the other lines in this method. Should we use add* for all of them ?
Also I can't move those lines up as the menu is not created yet. Or we should not use the default menu creation at all in this case.

Copy link
Member

Choose a reason for hiding this comment

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

insert*(menu.actions()[0], ...) adds an action top top, add*(...) adds to bottom. In my opinion spell checker actions are popular and should be on top, these ones are less popular and can be on bottom.

What do you mean by “not use the default menu creation at all”?

I think the solution is like this:

  • Always create the menu on top of this function, always append the move up/down actions;
  • Replace return QTextEdit.contextMenuEvent(self, event) with menu.exec(event.globalPos()).

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. I kinda rewrote the method to add the action even if we don't need the spellcheck, while keeping the spellcheck options on top, and the move at the bottom

ReText/window.py Outdated
@@ -336,6 +343,9 @@ def __init__(self, parent=None):
self.editBar.addAction(self.actionCopy)
self.editBar.addAction(self.actionPaste)
self.editBar.addSeparator()
self.editBar.addAction(self.actionMoveUp)
self.editBar.addAction(self.actionMoveDown)
self.editBar.addSeparator()
Copy link
Member

Choose a reason for hiding this comment

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

Is it really such a common action that it needs to be on the toolbar?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really, I can remove it if you prefer

ReText/editor.py Outdated
elif key == Qt.Key_Down and event.modifiers() & Qt.AltModifier:
self.moveLineDown()
elif key == Qt.Key_Up and event.modifiers() & Qt.AltModifier:
self.moveLineUp()
Copy link
Member

Choose a reason for hiding this comment

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

These lines are no longer needed, the shortcut is handled by QAction.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@xgouchet xgouchet force-pushed the alt_move_line branch 2 times, most recently from 662e90f to 0815042 Compare October 18, 2017 09:30
@mitya57
Copy link
Member

mitya57 commented Oct 18, 2017

By the way I have invited you to @retext-project, but please still make pull requests for non-trivial changes.

@xgouchet
Copy link
Member Author

Wow thanks man. And don't worry, I think I'll still make pull request anyway to get a second pair of eyes on my code !

Copy link
Member

@mitya57 mitya57 left a comment

Choose a reason for hiding this comment

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

You broke something :(

Now if I click on a spell check suggestion, the fixed word is inserted where the cursor was, not where right click was performed.

The previous behavior selected the wrong word on right click, and selecting a fixed word replaced that selection.

@xgouchet
Copy link
Member Author

Indeed, this should be fixed now

Copy link
Member

@mitya57 mitya57 left a comment

Choose a reason for hiding this comment

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

Hmm, now it selects the word and shows spell check suggestions even if the word is correct.

Also I noticed that if you right click outside a word (i.e. on a space between words) and select “Move line down” then it moves the wrong line down. Not one on which you clicked. Maybe unconditionally place the cursor to the click place before showing the menu?

Pressing Alt+Arrow Up / Alt+Arrow Down will move the current line
up/down. This is a nice feature to move lines without having to do a
Select-Cut-Move-Paste manipulation.
@xgouchet
Copy link
Member Author

Done

@mitya57 mitya57 merged commit 3dd85f6 into retext-project:master Oct 18, 2017
@xgouchet xgouchet deleted the alt_move_line branch October 19, 2017 04:14
@holzkohlengrill
Copy link

Don't know if that was intended or not but you cannot move multiple lines (only one).

I am commenting here since I don't know if this would be a new feature (if yes I will add this as a new issue) or if this is just a bug.

@mitya57
Copy link
Member

mitya57 commented Oct 30, 2018

I don't think moving multiple lines is a common task. And there is always Cut+Paste if you want that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants