From 773f4398f0d77e859fe5e36fcfb418469f14a640 Mon Sep 17 00:00:00 2001
From: Martyn Gigg <martyn.gigg@gmail.com>
Date: Tue, 29 May 2018 15:18:54 +0100
Subject: [PATCH] Pad executed code to keep vanilla line numbers correct

Python reports line numbers based on the code context it has. These
can be wrong if the selection is part of a larger file. Padding the code
then allows the raw numbers being reported to be used.
---
 qt/python/mantidqt/widgets/codeeditor/interpreter.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/qt/python/mantidqt/widgets/codeeditor/interpreter.py b/qt/python/mantidqt/widgets/codeeditor/interpreter.py
index 25571978366..7a530466634 100644
--- a/qt/python/mantidqt/widgets/codeeditor/interpreter.py
+++ b/qt/python/mantidqt/widgets/codeeditor/interpreter.py
@@ -91,7 +91,6 @@ class EditorIO(object):
 
 
 class PythonFileInterpreter(QWidget):
-
     sig_editor_modified = Signal(bool)
     sig_filename_modified = Signal(str)
 
@@ -233,7 +232,10 @@ class PythonFileInterpreterPresenter(QObject):
         else:
             code_str = editor.text()
             line_from = 0
-        return code_str, line_from
+        # Pad code out with empty lines so that reported line numbers
+        # do not have to be adjusted
+        padded = '\n'*line_from + code_str
+        return padded, line_from
 
     def _on_exec_success(self, task_result):
         self.view.editor.updateCompletionAPI(self.model.generate_calltips())
-- 
GitLab