diff --git a/@MBeautify/MBeautify.m b/@MBeautify/MBeautify.m index 086e67c..a2f0b5e 100644 --- a/@MBeautify/MBeautify.m +++ b/@MBeautify/MBeautify.m @@ -32,7 +32,7 @@ [result, nCurrentNewlines] = handleMaximalNewLines(line, nCurrentNewlines, maximalNewLines); - [codeBefore, codeToFormat, codeAfter, selectedPosition, additionalInfo] = handleSource(source); + [isSourceAvailable, codeBefore, codeToFormat, codeAfter, selectedPosition, additionalInfo] = handleSource(source); formattedSource = performFormatting(source, settingConf) writeConfigurationFile(resStruct, fullRulesConfMFileName); diff --git a/@MBeautify/beautify.m b/@MBeautify/beautify.m index 17504ab..92b3386 100644 --- a/@MBeautify/beautify.m +++ b/@MBeautify/beautify.m @@ -2,7 +2,10 @@ function beautify(source) % Handle the source -[codeBefore, codeToFormat, codeAfter, selectedPosition, additionalInfo] = MBeautify.handleSource(source); +[isSourceAvailable, codeBefore, codeToFormat, codeAfter, selectedPosition, additionalInfo] = MBeautify.handleSource(source); +if ~isSourceAvailable + return; +end currentSelection = selectedPosition; % Get the current configuration diff --git a/@MBeautify/handleSource.m b/@MBeautify/handleSource.m index 83ffbab..857df4c 100644 --- a/@MBeautify/handleSource.m +++ b/@MBeautify/handleSource.m @@ -1,8 +1,9 @@ -function [codeBefore, codeToFormat, codeAfter, selectedPosition, additionalInfo] = handleSource(source) +function [isSourceAvailable, codeBefore, codeToFormat, codeAfter, selectedPosition, additionalInfo] = handleSource(source) codeToFormat = ''; additionalInfo = []; - +isSourceAvailable = true; +selectedPosition = ''; sourceType = ''; if nargin < 1 @@ -31,11 +32,13 @@ currentEditorPage = matlab.desktop.editor.getActive(); - selectedPosition = currentEditorPage.Selection; - if isempty(currentEditorPage) + isSourceAvailable = false; return; end + selectedPosition = currentEditorPage.Selection; + + additionalInfo = currentEditorPage; codeToFormat = currentEditorPage.Text; @@ -46,6 +49,7 @@ if isempty(currentEditorPage) codeToFormat = ''; additionalInfo = []; + isSourceAvailable = false; return; end