Ticket #13 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

Copy/paste problems

Reported by: fperez Assigned to: tzanko
Priority: normal Milestone:
Component: nbshell Version:
Severity: normal Keywords:
Cc:

Description

I tried to highlight a section of code to paste, and I got the input prompt characters as well. In all highlight, copy/paste operation, the cell prompts should always be considered off-limits, so that users can copy/paste multiple lines of code without either the prompts or the '...' markers getting in the way.

A bit more diagnostics:

1. If I highlight a single line of valid python (say 'print 10'), I can copy (Ctrl-C) and paste (Ctrl-V) OK. Executing the pasted line works.

2. If, in a cell, I Shift-ArrowUp to naively pick up the previous cell, I get the prompts picked up. In that case, Ctrl-C is OK, but as soon as I hit Ctrl-V I get a traceback:

Traceback (most recent call last):
  File "/usr/local/home/fperez/usr/local/lib/python2.4/site-packages/nbshell/ipnNotebookWidget.py", line 32, in <lambda>
    wx.EVT_KEY_DOWN(self, lambda evt:CellCtrlBase.KeyDown(self,evt))
  File "/usr/local/home/fperez/usr/local/lib/python2.4/site-packages/nbshell/ipnNotebookWidget.py", line 86, in KeyDown
    self.OnKeyDown(evt)
  File "/home/fperez/usr/local/lib/python2.4/site-packages/nbshell/PythonWidget.py", line 347, in OnKeyDown
    self.Paste()
  File "/home/fperez/usr/local/lib/python2.4/site-packages/nbshell/PythonWidget.py", line 817, in Paste
    self.view.Paste()
  File "/home/fperez/usr/local/lib/python2.4/site-packages/nbshell/PythonPlugin.py", line 842, in Paste
    elif (wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_TEXT)) or
NameError: global name 'DF_UNICODETEXT' is not defined

After this, further attempts fail.

3. Highlighting multiline input seems to work if you start from the top of a multiline cell. While the highlight shadow covers the '....' continuation marks, the copy/paste operation works correctly. This is how it should also work if one starts the highlight from below (and the .... should not be highlighted).

Change History

09/07/05 14:44:08 changed by tzanko

  • status changed from new to assigned.

I fixed the bug which gave the traceback. I cannot highlight only the code without the prompts, because the Scintilla control does not allow it. However this is only a minor problem, since the copy/paste algorithm takes prompts into account.

There is one problem about pasting cells. Imagine you selected more than one cell and try to paste the selection inside another cell. What should be pasted? Currently when the cursor is at the end of the cell nbshell inserts the pasted cells after the current one, but when in the middle I simply paste the raw text including the prompts. What is the proper behaviour? Also, should I include prompts when I paste code in a text block?

09/07/05 17:02:24 changed by fperez

Addressing your comment: I think it's OK to include the whole 'flattened' selection when it includes multiple cells. It also seems like a reasonable behavior and a convenient way to merge cells.

But if possible, even if the highlight selection doesn't allow you to exclude the prompts, you should filter them out (if possible) from the in-memory data that actually gets put into the clipboard. Since the prompts cause invalid input, it would be best to simply not let them get to the clipboard at cut/copy time, rather than filtering them out at paste time.

09/07/05 17:29:54 changed by tzanko

This is how I implement copying/pasting:

When a selection is copied, nbshell creates three types of objects and puts them in the clipboard:

* a raw text object, which is used for pasting anywhere outside of code blocks

* a code object, which contains the code without the prompts and is created if the selection is within one cell

* a list of cells which is created if the selection consists of one or more whole cells.

According to the position of the caret during paste one of these objects is chosen and nbshell includes it in the documnet. So, in a sense, I do strip the prompts when I copy. I'll implement the new behaviour.

09/10/05 17:16:53 changed by tzanko

  • status changed from assigned to closed.
  • resolution set to fixed.

I'll concider the ticket closed for now. I implemented the behavior Fernando described in his last comment. However at the moment there is no direct way to paste a list of cells after the last cell. I had added an empty line at the end to fix that, but I couldn't update the cursor position properly, so that's gone now. This problem will have to be revisited when I implement better tracking and updating of the cursor position.

10/08/05 17:15:24 changed by anonymous

tyjghjghj'fjkhm,bm,b,.liyuoyur

'jjghm