@@ -33,9 +33,14 @@ import { notFoundError } from "@silverbulletmd/silverbullet/constants";
3333 */
3434export async function renamePageCommand ( cmdDef : any ) {
3535 const oldName : string = cmdDef . oldPage || await editor . getCurrentPage ( ) ;
36- const newName : string = cmdDef . page ||
36+ let newName : string = cmdDef . page ||
3737 await editor . prompt ( `Rename ${ oldName } to:` , oldName ) ;
38- if ( ! newName ) {
38+ if ( newName === undefined ) {
39+ return false ;
40+ }
41+ newName = newName . trim ( ) ;
42+ if ( newName === "" ) {
43+ editor . flashNotification ( "Must provide a non-empty page title." , "error" ) ;
3944 return false ;
4045 }
4146 const pageList : [ string , string ] [ ] = [ [ oldName + ".md" , newName + ".md" ] ] ;
@@ -66,8 +71,13 @@ export async function renamePageLinkCommand() {
6671 }
6772 const oldName = wikiLinkPage . children ! [ 0 ] . text ! ;
6873
69- const newName = await editor . prompt ( `Rename ${ oldName } to:` , oldName ) ;
70- if ( ! newName ) {
74+ let newName = await editor . prompt ( `Rename ${ oldName } to:` , oldName ) ;
75+ if ( newName === undefined ) {
76+ return false ;
77+ }
78+ newName = newName . trim ( ) ;
79+ if ( newName === "" ) {
80+ editor . flashNotification ( "Must provide a non-empty page title." , "error" ) ;
7181 return false ;
7282 }
7383 const pageList : [ string , string ] [ ] = [ [ oldName + ".md" , newName + ".md" ] ] ;
@@ -84,9 +94,17 @@ export async function renamePageLinkCommand() {
8494 */
8595export async function renameDocumentCommand ( cmdDef : any ) {
8696 const oldName : string = cmdDef . oldDocument || await editor . getCurrentPath ( ) ;
87- const newName : string = cmdDef . document ||
97+ let newName : string = cmdDef . document ||
8898 await editor . prompt ( `Rename ${ oldName } to:` , oldName ) ;
89- if ( ! newName ) {
99+ if ( newName === undefined ) {
100+ return false ;
101+ }
102+ newName = newName . trim ( ) ;
103+ if ( newName === "" ) {
104+ editor . flashNotification (
105+ "Must provide a non-empty document name." ,
106+ "error" ,
107+ ) ;
90108 return false ;
91109 }
92110 const pageList : [ string , string ] [ ] = [ [ oldName , newName ] ] ;
@@ -300,13 +318,19 @@ async function renameDocument(
300318export async function renamePrefixCommand ( cmdDef : any ) {
301319 const oldPrefix = cmdDef . oldPrefix ??
302320 await editor . prompt ( "Prefix to rename:" , "" ) ;
303- if ( ! oldPrefix ) {
321+ if ( oldPrefix === undefined ) {
322+ return false ;
323+ }
324+ // Note, we do *not* trim the old or new prefix input as the user may
325+ // actually want to add or remove white space. They can also input an empty
326+ // string for the new prefix to remove the old prefix.
327+ if ( oldPrefix === "" ) {
328+ editor . flashNotification ( "Must provide a non-empty prefix." , "error" ) ;
304329 return false ;
305330 }
306-
307331 const newPrefix = cmdDef . newPrefix ??
308332 await editor . prompt ( "New prefix:" , oldPrefix ) ;
309- if ( ! newPrefix ) {
333+ if ( newPrefix === undefined ) {
310334 return false ;
311335 }
312336
@@ -348,8 +372,12 @@ export async function extractToPageCommand() {
348372 newName = "new page" ;
349373 }
350374 newName = await editor . prompt ( `New page title:` , newName ) ;
351- if ( ! newName ) {
352- return ;
375+ if ( newName === undefined ) {
376+ return false ;
377+ }
378+ newName = newName . trim ( ) ;
379+ if ( newName === "" ) {
380+ editor . flashNotification ( "Must provide a non-empty page title." , "error" ) ;
353381 }
354382
355383 try {
0 commit comments