0

I have this macro that works as expected. I type any junk word for e.g. testd on a new line, place the cursor at the beginning of the word and run the macro. The word is added to standard dic. I can verify Tools - Spellings - options - standard dic - edit

Sub wort_einfuegen()
V_Cursor = ThisComponent.GetCurrentController.ViewCursor
T_Cursor = ThisComponent.text.createtextcursor()
T_Cursor.gotoRange(V_Cursor,false)

With T_Cursor
    .gotoEndofWord(True)
    re_text = .String
End with

dl = createUnoService ("com.sun.star.linguistic2.DictionaryList")
wb = dl.GetDictionaryByName("standard.dic")
wb.Add(re_text, False, "")

End sub

The problem is - if I type this word:

testी 

A blank line is added to the dict file. Is this a bug or this is expected behavior?


Update:

I think this must be a bug because I typed these 2 words :

भारत
इंडिया

Placed the cursor at the beginning of each word and run the same macro. The first word got added to the standard dic but the second word did not.

shantanuo
  • 31,689
  • 78
  • 245
  • 403

1 Answers1

1

For some reason, gotoEndOfWord() seems much less reliable than pressing Ctrl+Right Arrow. It looks like words ending in non-initial Devanagari vowels do not work. These do work:

इंडिय
इंडियात
testय
testओ

Anyway, the point is that way isn't very good. There are problems with some roman script words as well.

So why not do it with the dispatcher instead, which is similar to pressing the keys. Here is an example that correctly selects इंडिया.

Sub wort_einfuegen()
    frame = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
    dispatcher.executeDispatch(frame, ".uno:WordRightSel", "", 0, Array())
    V_Cursor = ThisComponent.GetCurrentController.ViewCursor
    re_text = V_Cursor.String
    MsgBox """" & re_text & """"
End Sub
Jim K
  • 12,824
  • 2
  • 22
  • 51
  • I have this macro where I need to update the way of selecting text. Can you suggest how to update this... https://github.com/shantanuo/spelling/blob/main/ListMisSpelledWords.txt – shantanuo Jul 03 '21 at 04:37
  • It looks like @HowardRudd is willing to write the code for you, so maybe he can adapt my answer. – Jim K Jul 03 '21 at 15:47
  • By the way, it seems you are familiar with Python, and that's normally what I use to write LibreOffice macros. The APSO extension is an easy way to run Python macros. Also a minor note: Your file on GitHub ends in .txt but I think it would be better to use .bas suffix as it is Basic code, not a plain text file. And please don't capitalize "S" in [misspelled](https://www.google.com/search?q=spell+misspelled). – Jim K Jul 03 '21 at 16:11
  • For anyone who comes across this answer later, HowardRudd incorporated the code here: https://stackoverflow.com/a/68248632/5100564 – Jim K Jul 06 '21 at 10:28
  • I will take a look at APSO extension. Do I need to install python? – shantanuo Jul 16 '21 at 11:33
  • On Windows, LibreOffice installs its own version of Python by default. On Linux, the system python is good enough, sometimes requiring an additional package such as `libreoffice-script-provider-python`. – Jim K Jul 16 '21 at 13:01