@@ -221,10 +221,14 @@ void QtSLiMTextEdit::highlightError(int startPosition, int endPosition)
221221
222222void QtSLiMTextEdit::selectErrorRange (EidosErrorContext &errorContext)
223223{
224- // If there is error-tracking information set, and the error is not attributed to a runtime script
225- // such as a lambda or a callback, then we can highlight the error range
226- if (!errorContext.executingRuntimeScript && (errorContext.errorPosition .characterStartOfErrorUTF16 >= 0 ) && (errorContext.errorPosition .characterEndOfErrorUTF16 >= errorContext.errorPosition .characterStartOfErrorUTF16 ))
227- highlightError (errorContext.errorPosition .characterStartOfErrorUTF16 , errorContext.errorPosition .characterEndOfErrorUTF16 + 1 );
224+ // If there is error-tracking information set, and the error is attributed to the user script,
225+ // then we can highlight the error range
226+ if ((!gEidosErrorContext .currentScript || (gEidosErrorContext .currentScript ->UserScriptUTF16Offset () == 0 )) &&
227+ (errorContext.errorPosition .characterStartOfErrorUTF16 >= 0 ) &&
228+ (errorContext.errorPosition .characterEndOfErrorUTF16 >= errorContext.errorPosition .characterStartOfErrorUTF16 ))
229+ {
230+ highlightError (errorContext.errorPosition .characterStartOfErrorUTF16 , errorContext.errorPosition .characterEndOfErrorUTF16 + 1 );
231+ }
228232}
229233
230234QPalette QtSLiMTextEdit::qtslimStandardPalette (void )
@@ -288,8 +292,7 @@ bool QtSLiMTextEdit::checkScriptSuppressSuccessResponse(bool suppressSuccessResp
288292{
289293 // Note this does *not* check out scriptString, which represents the state of the script when the Community object was created
290294 // Instead, it checks the current script in the script TextView – which is not used for anything until the recycle button is clicked.
291- QString currentScriptString = toPlainText ();
292- QByteArray utf8bytes = currentScriptString.toUtf8 ();
295+ QByteArray utf8bytes = toPlainText ().toUtf8 ();
293296 const char *cstr = utf8bytes.constData ();
294297 std::string errorDiagnostic;
295298
@@ -301,7 +304,7 @@ bool QtSLiMTextEdit::checkScriptSuppressSuccessResponse(bool suppressSuccessResp
301304 {
302305 if (scriptType == EidosScriptType)
303306 {
304- EidosScript script (cstr, - 1 );
307+ EidosScript script (cstr);
305308
306309 try {
307310 script.Tokenize ();
@@ -342,7 +345,7 @@ bool QtSLiMTextEdit::checkScriptSuppressSuccessResponse(bool suppressSuccessResp
342345
343346 EidosErrorContext errorContext = gEidosErrorContext ;
344347
345- gEidosErrorContext = EidosErrorContext{{- 1 , - 1 , - 1 , - 1 }, nullptr , false } ;
348+ ClearErrorContext () ;
346349
347350 selectErrorRange (errorContext);
348351
@@ -406,10 +409,9 @@ void QtSLiMTextEdit::_prettyprint_reformat(bool p_reformat)
406409 if (checkScriptSuppressSuccessResponse (true ))
407410 {
408411 // We know the script is syntactically correct, so we can tokenize and parse it without worries
409- QString currentScriptString = toPlainText ();
410- QByteArray utf8bytes = currentScriptString.toUtf8 ();
412+ QByteArray utf8bytes = toPlainText ().toUtf8 ();
411413 const char *cstr = utf8bytes.constData ();
412- EidosScript script (cstr, - 1 );
414+ EidosScript script (cstr);
413415
414416 script.Tokenize (false , true ); // get whitespace and comment tokens
415417
@@ -736,7 +738,7 @@ EidosFunctionMap *QtSLiMTextEdit::functionMapForScriptString(QString scriptStrin
736738 // This returns a function map (owned by the caller) that reflects the best guess we can make, incorporating
737739 // any functions known to our delegate, as well as all functions we can scrape from the script string.
738740 std::string script_string = scriptString.toStdString ();
739- EidosScript script (script_string, - 1 );
741+ EidosScript script (script_string);
740742
741743 // Tokenize
742744 script.Tokenize (true , false ); // make bad tokens as needed, don't keep nonsignificant tokens
@@ -825,7 +827,7 @@ EidosCallSignature_CSP QtSLiMTextEdit::signatureForScriptSelection(QString &call
825827 if (scriptString.length ())
826828 {
827829 std::string script_string = scriptString.toStdString ();
828- EidosScript script (script_string, - 1 );
830+ EidosScript script (script_string);
829831
830832 // Tokenize
831833 script.Tokenize (true , false ); // make bad tokens as needed, don't keep nonsignificant tokens
@@ -2323,7 +2325,7 @@ void QtSLiMTextEdit::_completionHandlerWithRangeForCompletion(NSRange *baseRange
23232325 delete definitive_function_map;
23242326
23252327 // Next, add type table entries based on parsing and analysis of the user's code
2326- EidosScript script (script_string, - 1 );
2328+ EidosScript script (script_string);
23272329
23282330 script.Tokenize (true , false ); // make bad tokens as needed, do not keep nonsignificant tokens
23292331 script.ParseInterpreterBlockToAST (true , true ); // make bad nodes as needed (i.e. never raise, and produce a correct tree)
@@ -2334,7 +2336,7 @@ void QtSLiMTextEdit::_completionHandlerWithRangeForCompletion(NSRange *baseRange
23342336 }
23352337
23362338 // Tokenize; we can't use the tokenization done above, as we want whitespace tokens here...
2337- EidosScript script (script_string, - 1 );
2339+ EidosScript script (script_string);
23382340 script.Tokenize (true , true ); // make bad tokens as needed, keep nonsignificant tokens
23392341
23402342 const std::vector<EidosToken> &tokens = script.Tokens ();
0 commit comments