Browse Source

* Fix inserting char inside a word
* Fix deleting chars

mazen 21 years ago
parent
commit
1faf78523f
1 changed files with 32 additions and 19 deletions
  1. 32 19
      rtl/objpas/freebidi.pp

+ 32 - 19
rtl/objpas/freebidi.pp

@@ -282,30 +282,43 @@ begin
   v2l := VisualToLogical(Dest, pDir);
   Result := v2l[0];
   if vp > Result
-  then
-    lp := Length(Dest) + 1
-  else
-    lp := v2l[vp];
-  c := Dest[lp];
-  if DirectionOf(c) = drRTL
   then
     begin
-      lp := lp + Length(c);
-      Result += 1;
+      lp := Length(Dest) + 1;
+      vp := Result;
     end
   else
-    Result := vp;
-  if DirectionOf(Src) = drRTL
-  then
+    lp := v2l[vp];
+  c := Dest[lp];
+  Result := vp;
+  case DirectionOf(c) of
+  drRTL:
     begin
-      Result := vp;
-      while (Result > 0) and (DirectionOf(Dest[v2l[Result]]) <> drLTR) do
-        Result -= 1;
-      while (Result < vp) and (DirectionOf(Dest[v2l[Result]]) <> drRTL) do
-        Result += 1;
-    end
+      lp += Length(c);
+      if DirectionOf(Src) <> drRTL
+      then
+        begin
+          while (Result <= Length(Dest)) and (DirectionOf(Dest[v2l[Result]]) <> drLTR) do
+            Result += 1;
+          while (Result > vp) and (DirectionOf(Dest[v2l[Result]]) <> drRTL) do
+            Result -= 1;
+          Result += 2;
+        end;
+    end;
+  drLTR:
+    Result += 1;
   else
-     Result += 1;
+    if DirectionOf(Src) = drRTL
+    then
+      begin
+        while (Result > 0) and (DirectionOf(Dest[v2l[Result]]) <> drLTR) do
+          Result -= 1;
+        while (Result < vp) and (DirectionOf(Dest[v2l[Result]]) <> drRTL) do
+          Result += 1;
+      end
+    else
+      Result += 1;
+  end;
   Insert(Src, Dest, lp);
 end;
 
@@ -326,7 +339,7 @@ var
 begin
   v2l := VisualToLogical(str, pDir);
   for i := 1 to v2l[0] do
-    if(v2l[i] < vp) and (v2l[i] > vp + len)
+    if(v2l[i] >= vp) and (v2l[i] < vp + len)
     then
       Delete(str, v2l[i], 1);
 end;