documentor: Fixed editing status on failed write
[sdk] / documentor / src / Documentor.ec
index 4a088c8..2cc1a7c 100644 (file)
@@ -2240,10 +2240,10 @@ class HelpView : HTMLView
       GetLastDirectory(location, fileName);
       StripLastDirectory(location, directory);
       archive = ArchiveOpen(archiveFile, { true } );
-      if(archive)
+      // if(archive)
       {
          TempFile f { };
-         ArchiveDir dir = archive.OpenDirectory(directory, null, replace);
+         ArchiveDir dir = archive ? archive.OpenDirectory(directory, null, replace) : null;
          Block block;
          bool empty = true;
          for(block = textBlock.parent.subBlocks.first; block; block = block.next)
@@ -2265,7 +2265,8 @@ class HelpView : HTMLView
             }
          }
          f.Seek(0, start);
-         dir.AddFromFile(fileName, f, null, replace, 0, null, null);
+         if(dir)
+            dir.AddFromFile(fileName, f, null, replace, 0, null, null);
          delete dir;
          delete archive;
          delete f;
@@ -2324,7 +2325,7 @@ class HelpView : HTMLView
          // Update overLink
          if(textBlock && overLink == textBlock.parent)
          {
-            selPosition = curPosition = TextPosFromPoint(x, y, &textBlock);
+            selPosition = curPosition = TextPosFromPoint(x, y, &textBlock, true);
             selBlock = textBlock;
             PositionCaret(true);
             selecting = true;
@@ -2341,12 +2342,14 @@ class HelpView : HTMLView
          HTMLView::OnLeftButtonUp(x, y, mods);
          if(edit)
          {
-            selPosition = curPosition = TextPosFromPoint(x, y, &textBlock);
+            selPosition = curPosition = TextPosFromPoint(x, y, &textBlock, true);
             selBlock = textBlock;
             PositionCaret(true);
             Update(null);
          }
       }
+      else
+         ReleaseCapture();
       selecting = false;
       return true;
    }
@@ -2356,7 +2359,7 @@ class HelpView : HTMLView
    {
       if(edit && selecting)
       {
-         curPosition = TextPosFromPoint(x, y, &textBlock);
+         curPosition = TextPosFromPoint(x, y, &textBlock, true);
          PositionCaret(true);
          Update(null);
       }
@@ -2365,32 +2368,38 @@ class HelpView : HTMLView
 
    bool OnLeftDoubleClick(int mx, int my, Modifiers mods)
    {
-      int c;
-      int start = -1;
-      int numBytes;
-      for(c = curPosition; c >= 0; c--)
-      {
-         unichar ch;
-         while(c > 0 && !UTF8_IS_FIRST(textBlock.text[c])) c--;
-         ch = UTF8GetChar(textBlock.text + c, &numBytes);
-         if(!CharMatchCategories(ch, letters|numbers|marks|connector))
-            break;
-         start = c;
-      }
-      if(start != -1)
+      if(edit && textBlock)
       {
-         for(c = start; c < textBlock.textLen; c += numBytes)
+         int c;
+         int start = -1;
+         int numBytes;
+
+         selPosition = curPosition = TextPosFromPoint(mx, my, &textBlock, false);
+         selBlock = textBlock;
+         for(c = curPosition; c >= 0; c--)
          {
-            unichar ch = UTF8GetChar(textBlock.text + c, &numBytes);
+            unichar ch;
+            while(c > 0 && !UTF8_IS_FIRST(textBlock.text[c])) c--;
+            ch = UTF8GetChar(textBlock.text + c, &numBytes);
             if(!CharMatchCategories(ch, letters|numbers|marks|connector))
                break;
+            start = c;
          }
-         selPosition = start;
-         curPosition = c;
+         if(start != -1)
+         {
+            for(c = start; c < textBlock.textLen; c += numBytes)
+            {
+               unichar ch = UTF8GetChar(textBlock.text + c, &numBytes);
+               if(!CharMatchCategories(ch, letters|numbers|marks|connector))
+                  break;
+            }
+            selPosition = start;
+            curPosition = c;
 
-         PositionCaret(true);
-         Update(null);
-         return false;
+            PositionCaret(true);
+            Update(null);
+            return false;
+         }
       }
       return true;
    }
@@ -3440,7 +3449,7 @@ class HelpView : HTMLView
    }
 
    // Returns a character offset into the TextBlock from a window coordinate
-   int TextPosFromPoint(int px, int py, Block * block)
+   int TextPosFromPoint(int px, int py, Block * block, bool half)
    {
       Block parentBlock = this.textBlock.parent;
       Block textBlock;
@@ -3509,7 +3518,7 @@ class HelpView : HTMLView
                   {
                      numBytes = UTF8_NUM_BYTES(ch);
                      display.FontExtent(textBlock.font.font, text + c, numBytes, &w, &th);
-                     if(/*py >= sy && */py < sy + th && /*px >= sx-w/2-space && */px < sx + w -w/2-space)
+                     if(/*py >= sy && */py < sy + th && /*px >= sx-w/2-space && */px < sx + (half ? w/2 : w) -space)
                         break;
                      sx += w;
                   }