Why there is a difference of 1 word in word count shown in TinyMCE editor and Function that returns text statistics for an editor instance by id - tinymce

I was trying to limit the word count in TinyMCE editor. For that used a function suggested in the documentation of TinyMCE https://www.tiny.cloud/docs-3x/howto/words/. This function always returns word count greater by 1 than the word count shown in the editor's status bar. For eg: if we empty the editor, the word count in status bar of editor shows 0 but function returns 1. Likewise the word count is 10 on editor, function returns 11. Why that function returns different value and how can I match these values?

The link you provide is to TinyMCE 3 documentation which is out of date. TinyMCE 5 is the currently released editor and TinyMCE 6 will be released shortly.
In TinyMCE 4+ you should use the API for the wordcount plugin which is documented here:
https://www.tiny.cloud/docs/plugins/opensource/wordcount/#api
If you use the wordcount API it will match what is displayed in the editor.
var wordcount = tinymce.activeEditor.plugins.wordcount;
console.log(wordcount.body.getWordCount());
console.log(wordcount.body.getCharacterCount());
console.log(wordcount.body.getCharacterCountWithoutSpaces());
console.log(wordcount.selection.getWordCount());
console.log(wordcount.selection.getCharacterCount());
console.log(wordcount.selection.getCharacterCountWithoutSpaces());

Related

How to make NUMPAGES show 1 less page?

I want the field NUMPAGES in MS Word to show the total page number of my document, minus exactly 1 page. I am trying to change the code with Ctrl+F9, but I can't seem to get the syntax right.
Use a field coded as:
{={NUMPAGES}-1}
Note: The field brace pairs (i.e. '{ }') for the above example are all created in the document itself, via Ctrl-F9 (Cmd-F9 on a Mac or, if you’re using a laptop, you might need to use Ctrl-Fn-F9); you can't simply type them or copy & paste them from this message.
{={ NUMPAGES \* MERGEFORMAT }-1}

MS WORD: how to use the page number in footer and use it in the text

I have a Word document, with the page number appearing in the footer.
And in the document I have a text saying something like this:
This document have X pages
Is there anyway to get the number in the document footer and automatically update the information in the text?
Thanks
Place your cursor where you want to have the page count appearing then follow these steps:
Place your cursor where you want to have the page count to appear
Ctrl + F9 -> Curly brackets will appear
Type NUMPAGES within the curly brackets
While the cursor is still within the curly brackets hit F9
Finished!
Assuming you have Microsoft Word 2007 or higher you can also do the same with these steps:
Place your cursor where you want to have the page count to appear
Insert -> Quick Parts -> Field...
Select NumPages on the left side
Click OK
Both ways provide you the exact same result.
You just inserted a so called Field in Microsoft Word representing the total page count of your document. It will automatically update once you print preview the document or when you place the cursor over the field and hit F9.
You can use many different fields for different purposes.
Update
According to your comment you want to have the total number of pages minus the first page. Microsoft describes how you can calculate the total number in such a case in their support article here.
Therefore use there steps:
Place your cursor where you want to have the page count to appear
Ctrl + F9 -> Curly brackets will appear
Enter =
Again press Ctrl + F9 -> another curly brackets will appear within the first ones
Type NUMPAGES within the second pair curly brackets
Enter - 1 after the second curly brackets but still within the first ones. Now it should look like this {={NUMPAGES} - 1}
While the cursor is still within the curly brackets hit F9
In case you have more then one front page just increase the number to subtract.

Microsoft Word restart page numbering

In MS Word for Windows 10, if you wish to restart page numbering from "1" in the middle of a large document, doing so is currently a 7 step process. For example, let's say you have a document with 4 sections and on each section you wanted to restart the page numbering from "1".
I had two related questions:
Is there a way that, not involving adding any code to the source material, that a user can restart page numbering with 1 or 2 steps as opposed to 7?
If no, did anybody have a script that would allow the functionality described above?
Thanks
You can set the page numbers to restart by right-clicking on the page number, selecting Format Page Numbers... from the context menu and then, in the dialog now opening, entering the desired start value. Seems easy enough to me actually.
If you want to make it simpler you can add the below macro to your Normal.dotm file. You can then add a button to your Quick Access Toolbar that you bind to the macro and the command will be a single click away.
Note that page numbering always works per section, so your document will already have to contain the respective sections.
Sub RestartPageNumbers()
Dim startingNumber As Integer
startingNumber = InputBox("Start page number at: ", "Restart Page Numbers", 1)
ActiveWindow.View.SeekView = WdSeekView.wdSeekCurrentPageFooter
With Selection.HeaderFooter.PageNumbers
.RestartNumberingAtSection = True
.startingNumber = startingNumber
End With
ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument
End Sub

How to increase visual length of form text field in Word?

When a form text field is inserted in a Word document, the grey shaded length is about 5 characters long. How can this length be increased?
Allthough it is a rather crude measure (and I don't recommend it), you can set "Properties -> Default Text" to as many blanks as you want the size. But this comes for a price: as long as you move into the field by pressing TAB, all blanks are selected and get typed over. When you use the mouse, you click the cursor anywhere into the field and start typing ... so your entry might be pre and post fixed by a number of blanks that you have to trim away in e.g. an exit macro.
I recommend old form fields as the last resort (i.e. there must be a good reason to use them) and would prefer (in that order)
native Word2010/2007 fields (text or Rich text - perhaps not backwords compatible)
legacy ActiveX fields (compatible with W2003)
Legacy (old) form fields

Formatting Objective-C code

I cut and paste Objective-C examples off Safari into Xcode but the formatting gets messed up. I know I can do multiple find and replace for { and \r, but is there a one button fix somewhere? Xcode option / plugin.
TextEdit plugin etc?
Answer: I created an AppleScript in TextWrangler
tell application "TextWrangler"
activate
replace "- (" using "\\r- (" searching in text 1 of text document "untitled text" options {search mode:literal, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
select find window
select text 1 of find window
replace ";" using ";\\r" searching in text 1 of text document "untitled text" options {search mode:literal, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
select find window
replace "{" using "{\\r" searching in text 1 of text document "untitled text" options {search mode:literal, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
select find window
replace "//" using "\\r//" searching in text 1 of text document "untitled text" options {search mode:literal, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
end tell
Control + I will do some degree of formatting on whatever text you have selected.
Re-indenting in Xcode 4 should solve most formatting issues you might have. However, if you're still not happy with the result, you'll have to go third-party.
I used to change my code formatting quite regularly. I'd go to update some old code, only to find that it was written using deprecated, now unfamiliar, formats.
I've been using Uncrustify to adapt old files to new formats. It's got quite a few options, but is still lacking. However, it should suffice for most cases.
Configure xcode's preferences such that tab always indents. Then go with whatever select-all-then-tab gives you for formatting. It is good enough and doing anything involving formatting that is not automatic is a complete waste of time.