Is it possible to move the location pointer up or down with MS Word Javascript API - ms-word

I am currently working on a plugin which will take voice commands and upon receiving a response from the server, act accordingly. For example if i say "delete word", the last word will be deleted. I want to be able to move the pointer left/right/up one line/down one line. Does Word Javascript API provide a way to achieve this?

There are no cursor movement APIs. But there are methods on the Paragraph object for getting the previous paragraph and the next paragraph. There are also ways to move among Ranges, if you can get a collection or an array of the ranges that you want to move around. And you can find the AdjacentAfter and AdjacentBefore ranges using the Range.compareLocationWith method. The Range object also has getNextRange and getNextRangeOrNullObject methods. Finally, the Range.select("Start") and Range.select("End") will put the cursor just before/after the current selected range.

Related

How do I reduce the number of 301 redirect entries using wildcards and variables in Squarespace?

I recently renamed all of the URLs that make up my blog... and have written redirects for almost every page... using wildcards where I can... keeping in mind... all that I know is the * wildcard at this time...
Here is an example of what I have...
/season-1/2017/1/1/snl-s01e01-host-george-carlin -> /season-1/snl-s01e01-george-carlin 301
I want to write a catch-all that will redirect all 38 seasons of reviews with one redirect entry... but I can't figure out how to get rid of just the word "host" between s01e01- and -george-carlin... and was thinking it would work something like this...
/season-*/*/*/*/snl-s*e*-host-*-* -> /season-*/snl-s*e*[code to remove the word "host"]-*-* 301
Is that even close to being correct? Do I need that many *s
Thanks in advance for any help...
Unfortunately, you won't be able to reduce the number of individual redirect entries using the redirect features that Squarespace has to offer, namely the wildcard (*) and a single variable ([name]). Multiple variables would be needed, but only [name] is supported.
The closest you can get is:
/season-1/*/*/*/snl-s01e01-host-[name] -> /season-1/snl-s01e01-[name] 301
But, if I'm understanding things, while the above redirect appears more general, it would still need to be copy/pasted for each post individually. So although it demonstrates the best that could be achieved, it is not a technical improvement.
Therefore, there are only two alternatives:
Create a Google Sheet (or other spreadsheet) where the old URLs are copy/pasted in column one, a formula using arrayformula and regular expressions to parse the old URL and generate the new URL is added in column two, and in column three a formula is written to join the two cells with -> and 301. With that done, you could click, drag and highlight all cells in column 3, copy, and paste them in the "URL Shortcuts" text area in Squarespace.It can be quite time consuming to figure out, write and test the correct formula, but it does avoid having to manually type out every redirect. Whether it is less time/effort in total depends on the number of redirects and one's proficiency with writing spreadsheet formulas.It could be that using the redirect code above would simplify the formula that'd need to be written in the spreadsheet, which may save some time.
Another alternative would be to remove your redirects and instead handle the redirect via JavaScript added to the 404/Page-not-found page. Because it sounds like you already have all of the redirects in place but are simply trying to reduce the overall number, I wouldn't recommend changing to a JavaScript-based approach. There are other drawbacks to using JavaScript, in any case.

How to create element from API with name from appropriate sequence?

I'd like to use EA to generate Requirement elements programatically. I need to use the same sequence numbering (REQ00000xy), as with the GUI when pressing "Auto" button in "Add Element ..." dialog in order to keep´consistent numbering for Requirement elements created either from GUI or from API.
Selecting the last used sequence number from already existing Requierement elements won't help, as it don't move the sequence number up and next Requirement created from GUI .
Is there a way to get (and properly use) the sequence number via EA API or EA SQL?
The table you're looking for is t_trxtypes. This contains something like (EA's output)
Description;NumericWeight;Notes;TRX;TRX_ID;Style;
Autocount;1,00;prefix=bla;suffix=x;active=1;active_a=0;counter=126;;Class;1; ;
You're interested in the column Notes which holds as CSV list like
prefix=bla;suffix=x;active=1;active_a=0;counter=126;
This is a test setting for a class which currently has the number 126. So the next created class would be named bla126x and the entry would change to
prefix=bla;suffix=x;active=1;active_a=0;counter=127;
Just keep the columne t_trxtypes.notes in synch with your creations.
Note EA does not (seem to) allow direct DB access. However, it has a proven back door:
Repository.Execute("UPDATE t_trxtypes SET Notes='prefix=bla;suffix=x;active=1;active_a=0;counter=127;' WHERE TRX_ID=<your id>")
will do the update (replace <your id> with the appropriate key). Though Execute is undocumented it works ever since and for sure Sparx will not limit it as nowadays everyone relies on it.
As a side note: This counter is not safe. There are lots of ways (the easiest is a simple rename) to break it. You'd need some script/add-in to have regular checks your numbering is still consistent. If you rely on requirement numbering you better use an external system like, I dare to say, DOORS.
Finally, RTFM....
For elements, where sequence is defined, if you use empty name in set =AddNew() function, EA generates the sequence upon .Update(). Not earlier. So if you plan to use the generated sequence and add some description, you need to create the element with empty name first, then Update() it and after that append your description to the content of the Name field.
As easy as this.

How to filter by both text and property in Chrome DevTool's network panel?

I want to filter Chrome DevTool's network panel by the method property and text in the URL. For example, if I am searching for the text chromequestion in the URL and only HTTP GET requests (ignore PUT, POST, DELETE, etc).
I am able to filter by text or by method:
I am not able to combine the filter to search by both text and method:
I read the documentation at https://developers.google.com/web/tools/chrome-devtools/network-performance/reference#filters and I am able to filter by multiple properties (.e.g, domain:*.com method:GET). However, I am unable to filter by text and property (e.g., method:GET chromequestion).
Unfortunately, it's not possible to do this currently. I played around in DevTools originally, but couldn't find a way. I later had a look into how the filtering was implemented, and can confirm there's a limitation preventing you from mixing the pre-defined filters and text filters.
Implementation details
This is a bit long but I thought it might be interesting for some to see how it's implemented. I will probably look into improving the implementation, either myself or I'll log it because it's limited.
There's a _parseFilterQuery function that parses the input field and categorises the entries into two arrays. The first is called filters, and it's the pre-defined filtering options, such as method:GET etc. The second is a text array filter, split up by spaces. The parser determines the difference fairly naively, by checking for the occurrence of :, and - at the start (for negation).
Scenario 1
You only input a pre-defined filter, or multiple filters. For each filter, the specific filter function, which looks at the different properties of the request object, is pushed to a network module filters array (this._filters). Later on, for each request, the function is called on it, and a match returns true, otherwise false. This will determine whether the request is shown. There's obviously a requirement for ALL filters to return true for the row to show.
Scenario 2
This is the interesting one, where you input both a pre-defined filter and a bit of text. This covers the Stack Overflow question. The _parseFilterQuery function looks at the text filters first, before the pre-defined ones. In Scenario 1, this was empty, so it was skipped.
We pass each text word to the _createTextFilter, and push each of the resulting filters to the network module filters array. However, the implementation of this is questionable. The only time the actual word passed in is used is to check whether its a negation filter for a bit of text. If the first character is -, it means the user doesn't want to see a request with the following word in the name. For example -icon means don't show any request with that in the name/page. If there is no negation, it simply returns the WHOLE input text as a regular expression, NOT the word passed in. In my case, it returns /method:GET icon/i.
The pre-defined filters are looked at next. In this case, method:GET is pushed.
Finally, it loops over the requests calling each filter on it. However, since the first filter is /method:GET icon/i, it makes ALL other filters redundant because it will NEVER pass. The text filters only apply to name and path, so method:GET in a text filter will be invalid.

Dropbox Api v2 - confusion with cursor and paging for list_folders

The files/list _folders method in api docs has the following for the description of the cursor parameter:
cursor - Pass the cursor into list_folder/continue to see what's changed in the folder since your previous query.
has_more - If true, then there are more entries available. Pass the cursor to list_folder/continue to retrieve the rest.
https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder
Which is it then? If I make another request to list_folders_continue passing in the token, am I requesting another page of results or changes to the folder? If I am requesting another page of results, what is the limit that was applied? And can I control that?
The docs also have the list_folder method under sharing, which appears to have more precise definition of the cursor and the support for the limit parameter
https://www.dropbox.com/developers/documentation/http/documentation#sharing-list_folders
Will the method under files have that too?
Which is it then? If I make another request to list_folders_continue passing in the token, am I requesting another page of results or changes to the folder?
It's both. The /files/list_folder/continue endpoint is used both for returning additional pages of items, as well as getting further updates in the future.
Each page returned by /files/list_folder[/continue] is limited in size, but there is no guaranteed limit, nor can you control that limit. Your app should just always check has_more and call back to /files/list_folder/continue if it is true.
Also, the endpoints /files/list_folder and /sharing/list_folders are different endpoints with different functionality.
The /files/list_folder endpoint is documented as:
Returns the contents of a folder.
The /sharing/list_folders endpoint is documented as:
Return the list of all shared folders the current user has access to.
The two endpoints use different cursors, for use with /files/list_folder/continue and /sharing/list_folders/continue, respectively.
Which is it then? If I make another request to list_folders_continue
passing in the token, am I requesting another page of results or
changes to the folder? If I am requesting another page of results,
what is the limit that was applied? And can I control that?
My own trial and error experimentation has determined that the "It's both" answer posted by Greg is not correct. Specifically, the correct answer is "it's either". See below for more details.
When you call files/list_folder and it returns the entire list of contents (with a has_more value of false), then the cursor returned is suitable for monitoring subsequent changes to the path specified by passing that cursor to files/list_folder/continue.
If files/list_folder returns the first of multiple pages of contents (with a has_more value of true), then the cursor returned is suitable for getting the next page of contents by passing it to files/list_folder/continue. This cursor is not suitable for monitoring for changes (try it yourself, you can call continue as many times as you want with that cursor and you will always get the second page of contents).
It's not entirely clear from the docs, but when getting pages of contents from files/list_folder/continue, each call will return a new cursor, and that new cursor must be passed to a subsequent call to files/list_folder/continue in order to get the next page. You must chain the cursors together in this way until you get the last page (where has_more is false).
The cursor returned in that last call to files/list_folder/continue can then be used in subsequent calls to files/list_folder/continue to monitor for changes to the original path specified in the very first call to files/list_folder.
So the cursor is either suitable for monitoring for changes (when it is returned with a has_more value of false) OR it is suitable for getting a subsequent page of contents (when it is returned with a has_more value of true), regardless of whether the call that produced the cursor was files/list_folder or files/list_folder/continue, but it is never both.

Data Processing, how to approach

I have the following Problem, given this XML Datastructure:
<level1>
<level2ElementTypeA></level2ElementTypeA>
<level2ElementTypeB>
<level3ElementTypeA>String1Ineed<level3ElementTypeB>
</level2ElementTypeB>
...
<level2ElementTypeC>
<level3ElementTypeB attribute1>
<level4ElementTypeA>String2Ineed<level4ElementTypeA>
<level3ElementTypeB>
<level2ElementTypeC>
...
<level2ElementTypeD></level2ElementTypeD>
</level1>
<level1>...</level1>
I need to create an Entity which contain: String1Ineed and String2Ineed.
So every time I came across a level3ElementTypeB with a certain value in attribute1, I have my String2Ineed. The ugly part is how to obtain String1Ineed, which is located in the first element of type level2ElementTypeB above the current level2ElementTypeC.
My 'imperative' solution looks like that that I always keep an variable with the last value of String1Ineed and if I hit criteria for String2Ineed, I simply use that. If we look at this from a plain collection processing point of view. How would you model the backtracking logic between String1Ineed and String2Ineed? Using the State Monad?
Isn't this what XPATH is for? You can find String2Ineed and then change the axis to search back for String1Ineed.