Force bold with IHTMLDocument - mshtml

I am using an HTML editing control build on MS HTML.
I need to be able to force text to be bold/unbold and cannot find an easy way to do this.
I can toggle bold status as follows:
(D as IHTMLDocument2).execCommand('Bold', False, EmptyParam);
I can get bold status as follows:
bIsBold := (D as IHTMLDocument2).queryCommandValue('Bold');
Now of course you will say, well duh, just get the bold status and then toggle it if you need to.
Unfortunately the selected text can actually have three states: not bold/partially bolded/all bold, so i am forced to blindly toggle the status before querying it to ensure it is only in the two know states: not bold/all bold. This is quite ugly so i would like to know if i am missing something obvious.
Thanks IA

Yes, but pressing the bold switch would then function expectedly (if one knows). Like in other editors.

Related

VS Code find-and-replace: is there a way to keep my previous find term when I type ctrl+h?

Currently, when I use ctrl+h with something highlighted, my find term is set equal to the highlighted text. Is there a way to stop that (and keep my find term the same as it was previously)?
Often I want to find-and-replace in VS Code, do something, highlight something, and then find-and-replace the same thing again. Is there a way to make it so that I don't have to retype my find term a second time?
I know there are some plugins that have this functionality; if you know of any that allow me to see both my find and replace terms at the same time, I would like to know.
Set this setting to false:
// Controls if we seed the search string in Find Widget from editor selection
"editor.find.seedSearchStringFromSelection": false,
Editor > Find: Seed Search String From Selection
Doing this will also affect your Find/Search in Files functionality.

How to insert keyboard key graphic representations into your document?

I'm working on a document describing keyboard shortcuts in GNOME and want to make text better looking than: ALT + TAB. A common way seems to be like in this thread where the buttons appear to be within the text:
https://unix.stackexchange.com/q/465681
Is this possible in LibreOffice in a proper way, or is it just inserting images inline? That doesn't seem like it would work every well with changing font size, etc. later, so I was hoping for a better solution.
You could insert real push buttons that don't do anything by following steps 1 thru 6 outlined at https://help.libreoffice.org/Common/Inserting_and_Editing_Buttons. But that approach, as well as inserting inline images, would be awkward because you'd have to worry at least about sizing, anchoring, and wrapping of surrounding text.
The approach you appear to be trying to avoid seems much more palatable, so long as you're not looking to exactly duplicate to Stack Exchange look.
As an example to demonstrate that it's workable, I did the following by applying the same Character formatting settings to each key word. This involved changing font family and size, setting light gray highlighting, adding a gray border, and changing left and right border padding from 0.02 to 0.06...
To make things easy, the settings could all be done with a single button press by creating a macro that could be applied to selected text. And since the result is just formatted text, there are no sizing, anchoring, or text wrapping issues to worry about.
One other option, as an alternative to significant text formatting, is to acquire and use a keyboard font, such as that discussed at How is the Keyboard font automatically styled as keyboard-like keys for the letters in Alt, Shift, Ctrl, Esc, and Backspace?. That would only require changing to that font to type in key representations.

Add HTML but not in text mode of TinyMCE

I have a big text and like to highlight words that are trademarks. So within this big CDATA node I need to grab for multiple words like "ACME Soda Chips" and make them red.
currently I do something like this in a TinyMCE plugin:
// almost ...
var foo = editor.getContent();
foo.replace('ACME Soda Chips', '<span class="douh">ACME Soda Chips</span>');
editor.setContent(foo);
My problem now is, that such HTML is displayed in Text-Mode (where you see the content as plain HTML) and also submitted therefor stored to the database.
But what I like to have is:
Highlight a word in the visual mode
Do not store my surrounding span somehow
Optional: Do not show that I used a span and CSS-class to highlight things.
Hint:
I may completely do this wrong - please help.
I read some other plugins and honestly I don't understand what they do.
Imagine the whole text as one single big CDATA part but I like to highlight a specific set out of it.

Avoid losing format after selecting all text and start typing

We use TinyMCE as the wysiwyg editor for our content builder. You can drag and drop a text module and once you click an edit button an TinyMCE instance will open. This works really well.
Problem is now that the builder is made for designers so a lot of the times you add a text module just for a 1 word heading or other cases where you only have one block. (one h1, one p etc.) You can also see this behavior in the official demos: Just add an lonely h2 heading, select all text and start to write.
Now Tiny MCE has the default behavior that if you select the complete text (which is almost always the case if you for example change an 1 line / word heading) and you start typing you will lose your formats completely. ( in our case: color, font-size, font-weight, line-height etc.)
This makes editing an heading for example really painful. Best workaround so far is to leave 1 character to not lose the format and then delete the character in the end.
I never saw that behavior in other editors so my question is: Is there maybe an easy setting or workaround to avoid this?
If there are situations where you want a root element to be something specific (e.g. <h2>) you can use the forced_root_block setting on that instance of TinyMCE to force a specific element:
https://www.tinymce.com/docs/configure/content-filtering/#forced_root_block
Even if you delete all text the new text will be wrapped with that root element. See this TinyMCE Fiddle for examples:
http://fiddle.tinymce.com/SOfaab
I think this would address your one line issue?

Make some text bold with autohotkey

I am an Autohotkey user. How can I make some text in clipboard having bold style. Actually, I want to get some text as input from clipboard and then change style (bold or unbold) of some words in there and eventually to paste the enhanced text to where it was previously copied. Also notice that the existing format of the text is important (thus using ClipboardAll) and I don't want to lose the original format; just to change / modify style of some words in there.
Any idea / clue to accomplish this?
Thanks
I assume you're working in word or some other text editor that allows Ctrl+B to bold highlighted text. Something like this should work.
clipboard =
ClipWait,,
OutVar := StrLen(clipboard)
;put code for navigating to your paste place here
send,^v
send,{Shift Down}
send,{Left %OutVar%}
send,{Shift Up}
send,^b
send,{end}
;send,%OutVar%
I'm kind of an amateur at this, but I tested it and it seems to work if you want to bold the entire clipboard. If you're bolding only certain words within a clipboard... I'm not sure. Personally, I would create a script that transfers the clipboard to Word or some other rich text editor, then use ^f to find the words I'm looking for (using input or InputBox), and then bolding those words in the style used above, and then copy/pasting the finished work to the final destination.
But there's probably an easier way to do it...
EDIT: InStr() might help you there... check the AutoHotkey help for more info about InStr().