p key pastes on a new line instead of just "Paste"

Bug #583822 reported by Yuriy Voziy
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
ViGedit
Confirmed
Undecided
Unassigned

Bug Description

In Vim the "p' key is pasting text right where the cursor is located, this correct and expected behaviour and also this alows to do
some tricks like:
  "xp" - swap chars in word
  "xwp" - swap words in string

vigedit pastes text from the new line which is unexpected behaviour for the "paste" command and also breaks previous vim experience.

Revision history for this message
Yuriy Voziy (yuretsz) wrote :

I've found how to almost fix this but I'm not as good enough with python

./bindings/command.py :line22
        self.reg(act.text.paste_ClipboardBelow, act.gtk.keysyms.p, after=act.modes.command, pos=True, **self.fr)
Replace with :
    self.reg(act.getMenu('paste'), act.gtk.keysyms.p, after=act.modes.command, pos=True, **self.fr)

But this behaviour is similar to Vim's "Shift+p" action which pastes before the cursor, not after it.
How can I paste after the cursor?

Revision history for this message
Yuriy Voziy (yuretsz) wrote :

Extended act.text with this method in actions/text.py

def paste_ClipboardAfter(act):
    act.pos.move_Forward(act)
    act.vibase.view.paste_clipboard()

And in bindings/command.py

# self.reg(act.text.paste_ClipboardAbove, act.gtk.keysyms.P, after=act.modes.command, pos=True, **self.fr)
# self.reg(act.text.paste_ClipboardBelow, act.gtk.keysyms.p, after=act.modes.command, pos=True, **self.fr)
        self.reg(act.getMenu('paste'), act.gtk.keysyms.P, after=act.modes.command, pos=True, **self.fr)
        self.reg(act.text.paste_ClipboardAfter, act.gtk.keysyms.p, after=act.modes.command, pos=True, **self.fr)

Now this works more similar to the Vim behaviour but I can't understand why the cursor moves to the beginning of the line after paste command.

Revision history for this message
Stephen Moore (delfick) wrote :

Hi,

vigedit isn't necessarily an exact clone of vim and does have differences. (since the beginning of this year I've realised just how much different, but nonetheless).

The problem we have here is when we're pasting the text, we don't actually know if we have a whole line or not and so I make it just to always paste on the next or previous line when pasting in command mode.

To make p and P in command mode paste inline, then you have what you suggested above, except we need a better method of keeping track of where the cursor was before the action.

The reason it keeps going back to the start of the line is because of this error (when you run gedit via the command line, you're able to see when things go wrong)

###########################
/home/iambob/.gnome2/gedit/plugins/ViGedit/cursor.py:36: GtkWarning: Invalid text buffer iterator: either the iterator is uninitialized, or the characters/pixbufs/widgets in the buffer have been modified since the iterator was created.
You must use marks, character numbers, or line numbers to preserve a position across buffer modifications.
You can apply tags and insert marks without invalidating your iterators,
but any mutation that affects 'indexable' buffer contents (contents that can be referred to by character offset)
will invalidate all outstanding iterators
  act.vibase.doc.place_cursor(newIter)
###########################

Unfortunately, my time is less than usual, so I can't look into it.

Sorry.....

Changed in vigedit:
status: New → Confirmed
Revision history for this message
Yuriy Voziy (yuretsz) wrote :

Yes, vigedit is not a clone, but it will be great to copy the best practice from Vim.

>> Unfortunately, my time is less than usual, so I can't look into it.

Do you have ideas why this can be happening? Python is not my language, but I can try to look into this.

Revision history for this message
Stephen Moore (delfick) wrote :

>> Yes, vigedit is not a clone, but it will be great to copy the best practice from Vim.

True.....

>> Do you have ideas why this can be happening? Python is not my language, but I can try to look into this.

Line 268 of vi.py says if the position needs to be preserved, then get the current state of the iter
Line 291 of vi.py says if the position needs to be preserved, then set the cursor back to the state it was back in line 268.

These use the getIter and moveInsert functions in cursor.py.

According to the error, we need to use marks instead of an iter. (this is more of a gtk thing, than a python thing)

The docs for pygtk are here http://www.pygtk.org/docs/pygtk/

TextMarks are described here http://www.pygtk.org/docs/pygtk/class-gtktextmark.html
act.vibase.doc gives the sourcebuffer associated with the current window, http://www.pygtk.org/pygtksourceview/class-gtksourcebuffer.html

Unfortunately, my knowledge of gtk is very limited, however the people in the #gedit IRC channel at irc.gnome.org should be helpful.

Revision history for this message
Stefan Bethge (kjyv) wrote :

This should also take into account if the lines we're copied/cut from visual mode or visual line mode. The first inserts from cursor, the second inserts from next line. Can we keep that info somewhere?

Revision history for this message
Stephen Moore (delfick) wrote :

I think the best that can be done there is to copy in the newline when doing the copy itself, depending on which visual mode is currently enabled. However there may be problems with that if copying on the first or last line (or when there is only one line to the file).

Unfortunately, I don't have time to even look at it and play around with any idea.

Sorry.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.