self.documentConstantIdentifier = self.documentConstantIdentifier\r
if not hasattr(self.rootNVDAObject.appModule, "_vbufRememberedCaretPositions"):\r
self.rootNVDAObject.appModule._vbufRememberedCaretPositions = {}\r
+ self._lastCaretPosition = None\r
\r
def prepare(self):\r
self.shouldPrepare=False\r
if not self.VBufHandle:\r
return\r
\r
- if self.shouldRememberCaretPositionAcrossLoads:\r
- try:\r
- caret = self.selection\r
- caret.collapse()\r
- self.rootNVDAObject.appModule._vbufRememberedCaretPositions[self.documentConstantIdentifier] = caret.bookmark\r
- except:\r
- pass\r
+ if self.shouldRememberCaretPositionAcrossLoads and self._lastCaretPosition:\r
+ self.rootNVDAObject.appModule._vbufRememberedCaretPositions[self.documentConstantIdentifier] = self._lastCaretPosition\r
\r
self.unloadBuffer()\r
\r
super(VirtualBuffer, self)._set_selection(info)\r
if isScriptWaiting() or not info.isCollapsed:\r
return\r
+ # Save the last caret position for use in terminate().\r
+ # This must be done here because the buffer might be cleared just before terminate() is called,\r
+ # causing the last caret position to be lost.\r
+ caret = info.copy()\r
+ caret.collapse()\r
+ self._lastCaretPosition = caret.bookmark\r
if config.conf['reviewCursor']['followCaret'] and api.getNavigatorObject() is self.rootNVDAObject:\r
api.setReviewPosition(info)\r
if reason == speech.REASON_FOCUS:\r