View Issue Details

IDProjectCategoryView StatusLast Update
0017619ScribusScripterpublic2025-09-09 19:56
Reporterale Assigned Toale  
PrioritynormalSeverityminorReproducibilityN/A
Status closedResolutionfixed 
Product Version1.7.1.svn 
Fixed in Version1.7.1.svn 
Summary0017619: Modify the behavior of scripter's selectText() and selectFrameText()
DescriptionCurrently, passing a length of 0 to selectText() "just" clears the selection.

I suggest to also move the cursor to pos.
TagsNo tags attached.
PatchYes

Relationships

related to 0017618 new [PATCH] Modify the behavior of scripter's getSelectedTextRange() 

Activities

ale

2025-09-06 15:17

manager   ~0053005

the attached patch:

- removes some dead code
- sets the cursor position after having created a new selection (as it happens when selecting with the mouse or keyboard)
- if the length of the selection is 0, then just move the cursor to that position (and remove any existing selection)
select-text-with-0-length.diff (1,262 bytes)   
From 96725481f39c7b2311435b3c088760c87bc0b618 Mon Sep 17 00:00:00 2001
From: ale rimoldi <ale@graphicslab.org>
Date: Sat, 6 Sep 2025 17:13:52 +0200
Subject: selectText() accepts 0 as length and just sets the cursor position;
 always set the selection at the end of the selection


diff --git a/scribus/plugins/scriptplugin/cmdtext.cpp b/scribus/plugins/scriptplugin/cmdtext.cpp
index de47752b8..bd6d35393 100644
--- a/scribus/plugins/scriptplugin/cmdtext.cpp
+++ b/scribus/plugins/scriptplugin/cmdtext.cpp
@@ -1273,21 +1273,10 @@ PyObject *scribus_selecttext(PyObject* /* self */, PyObject* args)
 		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot select text in a non-text frame", "python error").toLocal8Bit().constData());
 		return nullptr;
 	}
-	/* FIXME: not sure if we should make this check or not
-	if (start > ende)
-	{
-		PyErr_SetString(PyExc_ValueError, QString("Selection start > selection end").toLocal8Bit().constData());
-		return nullptr;
-	}
-	*/
 	item->itemText.deselectAll();
-	if (selcount == 0)
-	{
-		item->HasSel = false;
-		Py_RETURN_NONE;
-	}
 	item->itemText.select(start, selcount, true);
-	item->HasSel = true;
+	item->itemText.setCursorPosition(start + selcount);
+	item->HasSel = (selcount != 0);
 
 	Py_RETURN_NONE;
 }
select-text-with-0-length.diff (1,262 bytes)   

jghali

2025-09-07 10:32

administrator   ~0053006

Thanks, looks sensible. I applied your patch with a small modification and I also changed the behavior of selectFrameText() for consistency.

Issue History

Date Modified Username Field Change
2025-09-06 07:58 ale New Issue
2025-09-06 15:17 ale Note Added: 0053005
2025-09-06 15:17 ale File Added: select-text-with-0-length.diff
2025-09-06 15:18 ale Summary Modify the behavior of scripter's selectText() => [PATCH] Modify the behavior of scripter's selectText()
2025-09-06 15:18 ale Patch No => Yes
2025-09-07 10:32 jghali Summary [PATCH] Modify the behavior of scripter's selectText() => [PATCH] Modify the behavior of scripter's selectText() and selectFrameText()
2025-09-07 10:32 jghali Note Added: 0053006
2025-09-07 10:32 jghali Assigned To => ale
2025-09-07 10:32 jghali Status new => resolved
2025-09-07 10:32 jghali Resolution open => fixed
2025-09-07 10:32 jghali Fixed in Version => 1.7.1.svn
2025-09-07 17:40 jghali Summary [PATCH] Modify the behavior of scripter's selectText() and selectFrameText() => Modify the behavior of scripter's selectText() and selectFrameText()
2025-09-07 19:48 ale Relationship added related to 0017618
2025-09-09 19:56 cbradney Status resolved => closed