|
5 | 5 | Based on code contributed by A.M. Kuchling <amk at amk dot ca> |
6 | 6 |
|
7 | 7 | """ |
| 8 | +from editor.editor import Editor |
| 9 | + |
8 | 10 | import csv |
9 | 11 | import _curses |
10 | 12 | import curses |
@@ -405,62 +407,27 @@ def delete_row(self): |
405 | 407 |
|
406 | 408 | self.set_term_title(True) |
407 | 409 |
|
408 | | - def _edit_validator(self, ch): |
409 | | - """Fix Enter and backspace for textbox. |
410 | | -
|
411 | | - Used as an aux function for the textpad.edit method |
412 | | -
|
413 | | - """ |
414 | | - if ch == curses.ascii.NL: # Enter |
415 | | - return curses.ascii.BEL |
416 | | - elif ch == curses.KEY_HOME: |
417 | | - return self.textpad.do_command(KEY_CTRL('a')) |
418 | | - elif ch == curses.KEY_END: |
419 | | - return self.textpad.do_command(KEY_CTRL('e')) |
420 | | - elif ch == curses.ascii.ESC: |
421 | | - self.textpad.insert_mode = False |
422 | | - return curses.ascii.BEL |
423 | | - return ch |
424 | | - |
425 | 410 | def edit_cell(self, edit_existing=True): |
426 | 411 | yp = self.y + self.win_y |
427 | 412 | xp = self.x + self.win_x |
428 | 413 | self.box_height = self.max_y - int(self.max_y / 2) |
429 | | - box_height = int(self.box_height / 4) |
430 | | - from editor.editor import Editor |
431 | | - out = Editor(self.scr, inittext=self.data[yp][xp], win_location=(yp, xp), win_size=(self.max_y-box_height-1, self.max_x))() |
432 | | - self.data[yp][xp] = out |
433 | | - # yp = self.y + self.win_y |
434 | | - # xp = self.x + self.win_x |
435 | | - # self.box_height = self.max_y - int(self.max_y / 2) |
436 | | - # box_height = int(self.box_height / 4) |
437 | | - # |
438 | | - # prompt = "Edit: " |
439 | | - # scr2 = curses.newwin(box_height+1, self.max_x, self.max_y-box_height-1, 0) |
440 | | - # scr3 = scr2.derwin(1, self.max_x-len(prompt)-3, 1, len(prompt)+1) |
441 | | - # |
442 | | - # scr2.box() |
443 | | - # scr2.move(1, 1) |
444 | | - # |
445 | | - # addstr(scr2, prompt) |
446 | | - # if edit_existing: |
447 | | - # addstr(scr3, self.data[yp][xp]) |
448 | | - # |
449 | | - # scr2.refresh() |
450 | | - # curses.curs_set(1) |
451 | | - # |
452 | | - # self.textpad = Textbox(scr3, insert_mode=True) |
453 | | - # |
454 | | - # result = self.textpad.edit(self._edit_validator)[:-1].strip() |
455 | | - # if self.textpad.insert_mode: # False if escape pressed (discard) |
456 | | - # self.undo_buffer.insert(0, (yp, xp, self.data[yp][xp])) |
457 | | - # self.data[yp][xp] = result |
458 | | - # self.set_term_title(True) |
459 | | - # |
460 | | - # try: |
461 | | - # curses.curs_set(0) |
462 | | - # except _curses.error: |
463 | | - # pass |
| 414 | + self.term_rows, self.term_cols = self.scr.getmaxyx() |
| 415 | + data = self.data[yp][xp] if edit_existing else "" |
| 416 | + |
| 417 | + prompt = "Edit: " |
| 418 | + editor = Editor( |
| 419 | + self.scr, title=prompt, inittext=data, max_paragraphs=1, |
| 420 | + win_size=(int(self.term_rows / 2), self.term_cols), |
| 421 | + win_location=(self.box_height, 0), |
| 422 | + ) |
| 423 | + editor.end() # Move to end of text for easier editing |
| 424 | + |
| 425 | + result = editor().strip() |
| 426 | + if result != self.data[yp][xp]: |
| 427 | + self.undo_buffer.insert(0, (yp, xp, self.data[yp][xp])) |
| 428 | + self.data[yp][xp] = result |
| 429 | + self.set_term_title(True) |
| 430 | + curses.curs_set(0) |
464 | 431 |
|
465 | 432 | def undo_redo(self, undo=True): |
466 | 433 | if undo: |
|
0 commit comments