Ko/views title property strips all but the first leading underscore

The “title” property of, I believe, the views object, will fail to return all but the first leading underscore of a filename that has multiple underscores at the beginning of the name. For instance, one might have the following code in a userscript file:

var view = require( 'ko/views' ).current().get();
alert( view.title );

If that userscript file name begins with any legal character other than an underscore or with only one underscore, then it behaves as expected, and displays the correct filename in the JavaScript alert dialog. But if, for whatever reason, the userscript filename begins with two or more underscores, then only one of them is returned when the “title” property is accessed. Also, in the file’s tab in Komodo IDE, only that one underscore is displayed.

Here is an example, in which I created a new userscript file and named it “___title_test.js” (with three leading underscores, for better visibility), as seen in the first screenshot. In that script I placed the above code, and when I run the script, the alert dialog shows the front-truncated name. In the second screenshot here, you can see that the correct name is displayed in the far right panel, but the incorrect name is displayed in the tab and by the alert dialog.

At first I was reluctant to post this without first reading up on how the title property is supposed to work, but no such documentation appeared readily available. I’m probably not looking in the right place. Does anyone have any insight into why the title property is behaving this way and/or where I can read more about it and other similar properties? Thank you.

Does this happen on all files or just Userscripts (ie. toolbox items open in the editor)? I’m guessing this is the Toolbox doing name cleansing which though still wrong isn’t quite as negative.

  • Carey

I created a plain text file, ___Text-1.txt, and in the file tab, it does display all three leading underscores. But I don’t see a way to test the main problem of the “title” property stripping all but one of the underscores, since this is a text file and not a userscript within which I could run the code.

Just run the Userscript you already have. That gets the current open file view, not the Userscript itself. You just happened to have the Userscript open when you ran it, I’m assuming.

  • Carey

Thank you, Carey, for that info. Yes, I had the userscript open.

At the moment, that userscript isn’t readily available since I’m testing that other issue with a clean restart, so this time I opened the text file, ___Text-1.txt, and in the console simply ran the command
alert( require( 'ko/views' ).current().get().title );and all three leading underscores are displayed in the resulting text.

So this misbehavior apparently may be limited to userscripts.


What happens when you use alert(require("ko/views").current().basename)? That is what we would recommend people to use in a programming context. I think of title as “decorative”.

I’d say if basename works then we are Ok.

  • Carey

When trying that command, I get a syntax error, with unfortunately no helpful information.

I didn’t realize that that was an option. Where would I find documentation on that property? (I’m assuming it is different from the require( ‘ko/file’ ).basename() method.)

Same idea but no they aren’t related. Check your logs. That command works fine for me. Sorry about the terrible syntax error dialog.

  • Carey

The pystderr.log.txt log file did not contain anything related to syntax errors, so I simply commented out blocks of code until I found the problem – which turned out to be a silly little mistake I had made. The command you proposed worked.

As with the other property, when I have the userscript itself open and run the command alert(require("ko/views").current().basename), it too returns “_userscript_test.js”, with all but one of the leading underscores discarded.

Possibly related (but I don’t know because I’m not sure if it uses the same code), when I execute the command Clipboard - Copy View File Name, it also removes all but one of the leading underscores.

But when you open the userscript to edit it will have all the underscores?


Nvm, i just realized I could just not be lazy and try this myself. Yes, the name is the same in the property, ie. all underscores are included. This is silly. Even alert(require("ko/views").current().filePath) reports the wrong filename.

Thanks for your patience @mjross but I still think this isn’t worth looking further into. I can’t imagine someone hitting this while actually working. I suspect it was a fluke you even hit it. I filed a bug regardless so we’re aware of it.

  • Carey

Thank you, Carey, for your help on this and for filing the bug report.

Yes, it would be unlikely that most people (i.e., normal people :slight_smile: ) would name a file with two or more leading underscores. In my case, I started naming all of my personal userscripts with two leading underscores, so that in a (completely separate) PHP script I use for backing up all files, I could use the DOS file pattern “__*” since a single leading underscore is insufficient to distinguish them from all of the other Komodo-provided userscripts, which use underscores to separate individual words within the filename.

I’m still curious, do you know where there is any documentation for require( 'ko/views' ).current().get().title and require("ko/views").current().filePath? I’m trying to get up to speed on userscripts, and finding it a bit frustrating when trying to learn how to use properties and methods mentioned in the sample code – especially for anything related to ‘ko/views’.

@mjross, let’s start a new thread for this. It’s a good question but not quite related to this semi resolved thread.

  • Carey

Will do. Thanks!

To get the ball rolling: Macros and userscripts code differences