*/}}
Browse Source

Text edit improvements.

YimingWu 1 year ago
parent
commit
e75b8732ae
3 changed files with 25 additions and 13 deletions
  1. 6 3
      la_kernel.c
  2. 7 4
      resources/la_templates.c
  3. 12 6
      resources/la_widgets.c

+ 6 - 3
la_kernel.c

@@ -3226,9 +3226,12 @@ laPanel *laEnablePropertyPanel(laPanel *Attachment, laOperator *a, laPropPack *O
     int MinW;
 
     if (!def){
-        if (This && This->LastPs->p->UiDefine) def = This->LastPs->p->UiDefine;
-        if ((!def) && (sub=la_EnsureSubTarget(This->LastPs->p,This->EndInstance)) && sub->MenuUiDefine) def=sub->MenuUiDefine;
-        else def = FallBackUiDefine?FallBackUiDefine:laui_DefaultPropUiDefine;
+        if (This && This->LastPs->p){
+            if(This->LastPs->p->UiDefine) def = This->LastPs->p->UiDefine;
+            elif(This->LastPs->p->SubProp&&This->LastPs->p->SubProp->UiDefine) def = This->LastPs->p->SubProp->UiDefine;
+        }
+        if((!def) && (sub=la_EnsureSubTarget(This->LastPs->p,This->EndInstance)) && sub->MenuUiDefine) def=sub->MenuUiDefine;
+        if(!def) def = FallBackUiDefine?FallBackUiDefine:laui_DefaultPropUiDefine;
     }
 
     GX = L; GY = B;

+ 7 - 4
resources/la_templates.c

@@ -122,20 +122,23 @@ void laui_DefaultPropUiDefine(laUiList *uil, laPropPack *This, laPropPack *Opera
     }
 }
 void laui_StringPropUiDefine(laUiList *uil, laPropPack *This, laPropPack *Extra, laColumn *UNUSED, int context){
-    laColumn *c;
-    laProp *p, *gp;
+    laColumn *c; laProp *p, *gp;
 
     if (!This || !This->LastPs) return;
     c = laFirstColumn(uil);
-
     gp = This->LastPs->p;
 
     if(Extra){
-        laShowItem(uil, c, Extra, "copy_selection");
+        laShowItemFull(uil, c, Extra, "copy_selection",0,"mode=CUT;text=Cut;icon=✀",0,0);
+        laUiItem* b=laBeginRow(uil,c,0,0);
+        laShowItemFull(uil, c, Extra, "copy_selection",0,"text=Copy",0,0)->Expand=1;
+        laShowItemFull(uil, c, This, "copy",0,"text=All",0,0);
+        laEndRow(uil,b);
     }else{
         laShowItem(uil, c, This, "copy");
     }
     laShowItem(uil, c, This, "paste");
+    laShowSeparator(uil,c);
     laShowItem(uil, c, This, "restore");
     if(gp->Tag&LA_PROP_IS_FILE){ laShowItem(uil, c, This, "get_file_path"); }
     if(gp->Tag&LA_PROP_IS_FOLDER){ laShowItem(uil, c, This, "get_folder_path"); }

+ 12 - 6
resources/la_widgets.c

@@ -1078,10 +1078,10 @@ void la_MultiStringDraw(laUiItem *ui, int h){
         int len=strlenU(sl->Buf); 
         if(UseLine==se->CursorLine){
             int Dist=se->CursorBefore==0?0:tnsStringGetWidthU(sl->Buf,se->CursorBefore,ui->Flags&LA_TEXT_MONO);
-            tnsUseNoTexture(); int d=se->ViewStartCol*MonoWidth;
+            tnsUseNoTexture(); int d=se->ViewStartCol*MonoWidth; real w2=LA_RH/12;
             tnsColor4dv(ui->State==LA_UI_ACTIVE?laAccentColor(LA_BT_TEXT):laThemeColor(bt,LA_BT_TEXT_NORMAL));
-            tnsVertex2d(_L+Dist-d, LineU); tnsVertex2d(_L+Dist+3-d, LineU);
-            tnsVertex2d(_L+Dist-d, LineU+LA_RH); tnsVertex2d(_L+Dist+3-d, LineU+LA_RH);
+            tnsVertex2d(_L+Dist-w2-d, LineU); tnsVertex2d(_L+Dist+w2-d, LineU);
+            tnsVertex2d(_L+Dist-w2-d, LineU+LA_RH); tnsVertex2d(_L+Dist+w2-d, LineU+LA_RH);
             tnsPackAs(GL_QUADS);
         }
         Line++;
@@ -1743,6 +1743,7 @@ void la_RegisterUiTypesBasic(){
     _LA_UI_STRING->GetMinWidth = la_StringPropGetMinWidth;
     km=&_LA_UI_STRING->KeyMapper;
     laAssignNewKey(km, 0, "LA_edit_string_copy", LA_KM_SEL_UI_EXTRA, LA_KEY_CTRL, LA_KEY_DOWN, 'c', 0);
+    laAssignNewKey(km, 0, "LA_edit_string_copy", LA_KM_SEL_UI_EXTRA, LA_KEY_CTRL, LA_KEY_DOWN, 'x', "mode=CUT");
     laAssignNewKey(km, 0, "LA_system_paste", 0, LA_KEY_CTRL, LA_KEY_DOWN, 'v', 0);
     pc=laUiHasExtraProps(_LA_UI_STRING, sizeof(laGeneralUiExtraData), 0);{
         laAddOperatorProperty(pc, "copy_selection", "Copy Selection", "Copy selected string into clipboard", "LA_edit_string_copy",0,0);
@@ -1754,6 +1755,7 @@ void la_RegisterUiTypesBasic(){
     _LA_UI_STRING_MULTI->GetMinWidth = la_StringPropGetMinWidth;
     km=&_LA_UI_STRING_MULTI->KeyMapper;
     laAssignNewKey(km, 0, "LA_edit_string_copy", LA_KM_SEL_UI_EXTRA, LA_KEY_CTRL, LA_KEY_DOWN, 'c', 0);
+    laAssignNewKey(km, 0, "LA_edit_string_copy", LA_KM_SEL_UI_EXTRA, LA_KEY_CTRL, LA_KEY_DOWN, 'x', "mode=CUT");
     laAssignNewKey(km, 0, "LA_system_paste", 0, LA_KEY_CTRL, LA_KEY_DOWN, 'v', 0);
     pc=laUiHasExtraProps(_LA_UI_STRING_MULTI, sizeof(laGeneralUiExtraData), 0);{
         laAddOperatorProperty(pc, "copy_selection", "Copy Selection", "Copy selected string into clipboard", "LA_edit_string_copy",0,0);
@@ -1857,9 +1859,13 @@ int OPINV_EditStringCopySelection(laOperator *a, laEvent *e){
     laGeneralUiExtraData *uit = a->This->EndInstance; if(!uit) return LA_FINISHED;
     if(!uit->Edit || !strHasSelection(uit->Edit)) return LA_FINISHED;
 
+    char* mode=strGetArgumentString(a->ExtraInstructionsP,"mode");
+
     char* str=strGetEditString(uit->Edit, 1);
     laCopyToClipboard(str); free(str);
 
+    if(strSame(mode,"CUT")){ strClearSelection(&uit->Edit); }
+
     return LA_FINISHED;
 }
 
@@ -1888,14 +1894,14 @@ int la_ProcessTextEdit(laEvent *e, laStringEdit *se, laUiItem* ui){
     case LA_L_MOUSE_DOWN:
     case LA_MOUSEMOVE:
         if(!ui) return 0;
-        MonoWidth=tnsGetMonoFontAdvance(); _L=(*ui->Type->Theme)->LM+ui->L;
+        MonoWidth=tnsGetMonoFontAdvance(); _L=(*ui->Type->Theme)->LM*2+ui->L;
         int Count=se->TotalLines; while(Count){ Count/=10; _L+=MonoWidth; }
         if(e->Type==LA_L_MOUSE_DOWN){
-            strSetCursor(se, (e->y-ui->U)/LA_RH+se->ViewStartLine, (e->x-_L-MonoWidth/2)/MonoWidth); strCancelSelect(se); strLazySelect(se);
+            strSetCursor(se, (e->y-ui->U)/LA_RH+se->ViewStartLine, (real)se->ViewStartCol+((real)e->x-_L)/MonoWidth+0.5); strCancelSelect(se); strLazySelect(se);
             se->MouseSelecting=1; se->CursorPreferBefore=se->CursorBefore; return 1;
         }else{
             if(!se->MouseSelecting) return 0;
-            strSetCursor(se, (e->y-ui->U)/LA_RH+se->ViewStartLine, (e->x-_L-MonoWidth/2)/MonoWidth); strEndSelect(se);
+            strSetCursor(se, (e->y-ui->U)/LA_RH+se->ViewStartLine, (real)se->ViewStartCol+((real)e->x-_L)/MonoWidth+0.5); strEndSelect(se);
             se->CursorPreferBefore=se->CursorBefore; return 1;
         }return 0;
     case LA_L_MOUSE_UP: