prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  'v' (wrap text) reloads from source, undoing sheet modifications
  I've noticed some odd side effects when using 'v' (text wrapping).
  - When a row has been deleted (d), and then wrapping applied (v) the row will reappear
  
  To test:
  echo -e "abc\nDELETEME\n123\n456" | vd -
  - delete the row DELETEME with 'd'
  - Now apply wrapping with 'v'
  The DELETEME row appears
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `visidata/textsheet.py`
  Content:
  ```
  1 import textwrap
  2 
  3 from visidata import vd, option, options, Sheet, ColumnItem, asyncthread
  4 from visidata import globalCommand, error, stacktrace, VisiData
  5 
  6 __all__ = ['TextSheet', 'ErrorSheet']
  7 
  8 
  9 option('wrap', False, 'wrap text to fit window width on TextSheet')
  10 option('save_filetype', 'tsv', 'specify default file type to save as', replay=True)
  11 
  12 
  13 ## text viewer
  14 # rowdef: (linenum, str)
  15 class TextSheet(Sheet):
  16     'Displays any iterable source, with linewrap if wrap set in init kwargs or options.'
  17     rowtype = 'lines'
  18     filetype = 'txt'
  19     columns = [
  20         ColumnItem('linenum', 0, type=int, width=0),
  21         ColumnItem('text', 1),
  22     ]
  23 
  24     def iterload(self):
  25         winWidth = min(self.columns[1].width or 78, self.windowWidth-2)
  26         wrap = options.wrap
  27         for startingLine, text in enumerate(self.source):
  28             if wrap and text:
  29                 for i, L in enumerate(textwrap.wrap(str(text), width=winWidth)):
  30                     yield [startingLine+i+1, L]
  31             else:
  32                 yield [startingLine+1, text]
  33 
  34 
  35 # .source is Sheet error came from
  36 # .lines is list of source text lines to 'load'
  37 class ErrorSheet(TextSheet):
  38     precious = False
  39     def iterload(self):
  40         'Uses .lines; .source is sheet causing the error.'
  41         for i, line in enumerate(self.lines):
  42             yield [i, line]
  43 
  44 @VisiData.property
  45 def allErrorsSheet(self):
  46     return ErrorSheet("errors_all", lines=sum(vd.lastErrors, []))
  47 
  48 @VisiData.property
  49 def recentErrorsSheet(self):
  50     return ErrorSheet("errors_recent", lines=sum(vd.lastErrors[-1:], []))
  51 
  52 
  53 globalCommand('^E', 'error-recent', 'vd.lastErrors and vd.push(recentErrorsSheet) or status("no error")', 'view traceback for most recent error')
  54 globalCommand('g^E', 'errors-all', 'vd.push(vd.allErrorsSheet)', 'view traceback for most recent errors')
  55 
  56 Sheet.addCommand(None, 'view-cell', 'vd.push(ErrorSheet("%s[%s].%s" % (name, cursorRowIndex, cursorCol.name), source=sheet, lines=cursorDisplay.splitlines()))', 'view contents of current cell in a new sheet'),
  57 Sheet.addCommand('z^E', 'error-cell', 'vd.push(ErrorSheet(sheet.name+"_cell_error", source=sheet, lines=getattr(cursorCell, "error", None) or fail("no error this cell")))', 'view traceback for error in current cell')
  58 
  59 TextSheet.addCommand('v', 'visibility', 'sheet.options.wrap = not sheet.options.wrap; reload(); status("text%s wrapped" % ("" if sheet.options.wrap else " NOT")); ')
  60 
  61 TextSheet.options.save_filetype = 'txt'
  62
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/visidata/textsheet.py b/visidata/textsheet.py
  --- a/visidata/textsheet.py
  +++ b/visidata/textsheet.py
  @@ -56,6 +56,4 @@
   Sheet.addCommand(None, 'view-cell', 'vd.push(ErrorSheet("%s[%s].%s" % (name, cursorRowIndex, cursorCol.name), source=sheet, lines=cursorDisplay.splitlines()))', 'view contents of current cell in a new sheet'),
   Sheet.addCommand('z^E', 'error-cell', 'vd.push(ErrorSheet(sheet.name+"_cell_error", source=sheet, lines=getattr(cursorCell, "error", None) or fail("no error this cell")))', 'view traceback for error in current cell')
   
  -TextSheet.addCommand('v', 'visibility', 'sheet.options.wrap = not sheet.options.wrap; reload(); status("text%s wrapped" % ("" if sheet.options.wrap else " NOT")); ')
  -
   TextSheet.options.save_filetype = 'txt'
  
verification_info: {"golden_diff": "diff --git a/visidata/textsheet.py b/visidata/textsheet.py\n--- a/visidata/textsheet.py\n+++ b/visidata/textsheet.py\n@@ -56,6 +56,4 @@\n Sheet.addCommand(None, 'view-cell', 'vd.push(ErrorSheet(\"%s[%s].%s\" % (name, cursorRowIndex, cursorCol.name), source=sheet, lines=cursorDisplay.splitlines()))', 'view contents of current cell in a new sheet'),\n Sheet.addCommand('z^E', 'error-cell', 'vd.push(ErrorSheet(sheet.name+\"_cell_error\", source=sheet, lines=getattr(cursorCell, \"error\", None) or fail(\"no error this cell\")))', 'view traceback for error in current cell')\n \n-TextSheet.addCommand('v', 'visibility', 'sheet.options.wrap = not sheet.options.wrap; reload(); status(\"text%s wrapped\" % (\"\" if sheet.options.wrap else \" NOT\")); ')\n-\n TextSheet.options.save_filetype = 'txt'\n", "issue": "'v' (wrap text) reloads from source, undoing sheet modifications\nI've noticed some odd side effects when using 'v' (text wrapping).\r\n- When a row has been deleted (d), and then wrapping applied (v) the row will reappear\r\n\r\nTo test:\r\necho -e \"abc\\nDELETEME\\n123\\n456\" | vd -\r\n- delete the row DELETEME with 'd'\r\n- Now apply wrapping with 'v'\r\nThe DELETEME row appears\n", "before_files": [{"content": "import textwrap\n\nfrom visidata import vd, option, options, Sheet, ColumnItem, asyncthread\nfrom visidata import globalCommand, error, stacktrace, VisiData\n\n__all__ = ['TextSheet', 'ErrorSheet']\n\n\noption('wrap', False, 'wrap text to fit window width on TextSheet')\noption('save_filetype', 'tsv', 'specify default file type to save as', replay=True)\n\n\n## text viewer\n# rowdef: (linenum, str)\nclass TextSheet(Sheet):\n    'Displays any iterable source, with linewrap if wrap set in init kwargs or options.'\n    rowtype = 'lines'\n    filetype = 'txt'\n    columns = [\n        ColumnItem('linenum', 0, type=int, width=0),\n        ColumnItem('text', 1),\n    ]\n\n    def iterload(self):\n        winWidth = min(self.columns[1].width or 78, self.windowWidth-2)\n        wrap = options.wrap\n        for startingLine, text in enumerate(self.source):\n            if wrap and text:\n                for i, L in enumerate(textwrap.wrap(str(text), width=winWidth)):\n                    yield [startingLine+i+1, L]\n            else:\n                yield [startingLine+1, text]\n\n\n# .source is Sheet error came from\n# .lines is list of source text lines to 'load'\nclass ErrorSheet(TextSheet):\n    precious = False\n    def iterload(self):\n        'Uses .lines; .source is sheet causing the error.'\n        for i, line in enumerate(self.lines):\n            yield [i, line]\n\n@VisiData.property\ndef allErrorsSheet(self):\n    return ErrorSheet(\"errors_all\", lines=sum(vd.lastErrors, []))\n\n@VisiData.property\ndef recentErrorsSheet(self):\n    return ErrorSheet(\"errors_recent\", lines=sum(vd.lastErrors[-1:], []))\n\n\nglobalCommand('^E', 'error-recent', 'vd.lastErrors and vd.push(recentErrorsSheet) or status(\"no error\")', 'view traceback for most recent error')\nglobalCommand('g^E', 'errors-all', 'vd.push(vd.allErrorsSheet)', 'view traceback for most recent errors')\n\nSheet.addCommand(None, 'view-cell', 'vd.push(ErrorSheet(\"%s[%s].%s\" % (name, cursorRowIndex, cursorCol.name), source=sheet, lines=cursorDisplay.splitlines()))', 'view contents of current cell in a new sheet'),\nSheet.addCommand('z^E', 'error-cell', 'vd.push(ErrorSheet(sheet.name+\"_cell_error\", source=sheet, lines=getattr(cursorCell, \"error\", None) or fail(\"no error this cell\")))', 'view traceback for error in current cell')\n\nTextSheet.addCommand('v', 'visibility', 'sheet.options.wrap = not sheet.options.wrap; reload(); status(\"text%s wrapped\" % (\"\" if sheet.options.wrap else \" NOT\")); ')\n\nTextSheet.options.save_filetype = 'txt'\n", "path": "visidata/textsheet.py"}], "after_files": [{"content": "import textwrap\n\nfrom visidata import vd, option, options, Sheet, ColumnItem, asyncthread\nfrom visidata import globalCommand, error, stacktrace, VisiData\n\n__all__ = ['TextSheet', 'ErrorSheet']\n\n\noption('wrap', False, 'wrap text to fit window width on TextSheet')\noption('save_filetype', 'tsv', 'specify default file type to save as', replay=True)\n\n\n## text viewer\n# rowdef: (linenum, str)\nclass TextSheet(Sheet):\n    'Displays any iterable source, with linewrap if wrap set in init kwargs or options.'\n    rowtype = 'lines'\n    filetype = 'txt'\n    columns = [\n        ColumnItem('linenum', 0, type=int, width=0),\n        ColumnItem('text', 1),\n    ]\n\n    def iterload(self):\n        winWidth = min(self.columns[1].width or 78, self.windowWidth-2)\n        wrap = options.wrap\n        for startingLine, text in enumerate(self.source):\n            if wrap and text:\n                for i, L in enumerate(textwrap.wrap(str(text), width=winWidth)):\n                    yield [startingLine+i+1, L]\n            else:\n                yield [startingLine+1, text]\n\n\n# .source is Sheet error came from\n# .lines is list of source text lines to 'load'\nclass ErrorSheet(TextSheet):\n    precious = False\n    def iterload(self):\n        'Uses .lines; .source is sheet causing the error.'\n        for i, line in enumerate(self.lines):\n            yield [i, line]\n\n@VisiData.property\ndef allErrorsSheet(self):\n    return ErrorSheet(\"errors_all\", lines=sum(vd.lastErrors, []))\n\n@VisiData.property\ndef recentErrorsSheet(self):\n    return ErrorSheet(\"errors_recent\", lines=sum(vd.lastErrors[-1:], []))\n\n\nglobalCommand('^E', 'error-recent', 'vd.lastErrors and vd.push(recentErrorsSheet) or status(\"no error\")', 'view traceback for most recent error')\nglobalCommand('g^E', 'errors-all', 'vd.push(vd.allErrorsSheet)', 'view traceback for most recent errors')\n\nSheet.addCommand(None, 'view-cell', 'vd.push(ErrorSheet(\"%s[%s].%s\" % (name, cursorRowIndex, cursorCol.name), source=sheet, lines=cursorDisplay.splitlines()))', 'view contents of current cell in a new sheet'),\nSheet.addCommand('z^E', 'error-cell', 'vd.push(ErrorSheet(sheet.name+\"_cell_error\", source=sheet, lines=getattr(cursorCell, \"error\", None) or fail(\"no error this cell\")))', 'view traceback for error in current cell')\n\nTextSheet.options.save_filetype = 'txt'\n", "path": "visidata/textsheet.py"}]}