Keep cursor stable as doc changes before it