mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
Make paragraph editable on doubleclick if editOnDblClick set true in interpreter-setting.json
This commit is contained in:
parent
359dc0b67b
commit
93abe6aa92
5 changed files with 84 additions and 27 deletions
|
|
@ -12,7 +12,8 @@
|
|||
}
|
||||
},
|
||||
"editor": {
|
||||
"language": "markdown"
|
||||
"language": "markdown",
|
||||
"editOnDblClick": "true"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -139,6 +139,10 @@
|
|||
// register mouseevent handler for focus paragraph
|
||||
document.addEventListener('keydown', $scope.keyboardShortcut);
|
||||
|
||||
$scope.paragraphOnDoubleClick = function(paragraphId) {
|
||||
$scope.$broadcast('doubleClickParagraph', paragraphId);
|
||||
};
|
||||
|
||||
/** Remove the note and go back tot he main page */
|
||||
/** TODO(anthony): In the nearly future, go back to the main page and telle to the dude that the note have been remove */
|
||||
$scope.removeNote = function(noteId) {
|
||||
|
|
@ -352,7 +356,7 @@
|
|||
} else {
|
||||
$scope.viewOnly = $scope.note.config.looknfeel === 'report' ? true : false;
|
||||
}
|
||||
$scope.note.paragraphs[0].focus = true;
|
||||
//$scope.note.paragraphs[0].focus = true;
|
||||
$rootScope.$broadcast('setLookAndFeel', $scope.note.config.looknfeel);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -113,7 +113,8 @@ limitations under the License.
|
|||
ng-include src="'app/notebook/paragraph/paragraph.html'"
|
||||
ng-class="{'paragraph-space box paragraph-margin': !asIframe, 'focused': paragraphFocused,
|
||||
'lastEmptyParagraph': !paragraph.text && !paragraph.result}"
|
||||
ng-hide="currentParagraph.config.tableHide && viewOnly">
|
||||
ng-hide="currentParagraph.config.tableHide && viewOnly"
|
||||
ng-dblclick="paragraphOnDoubleClick(currentParagraph.id);">
|
||||
</div>
|
||||
<div class="new-paragraph" ng-click="insertNew('below');" ng-hide="!$last || viewOnly || asIframe ">
|
||||
<h4 class="plus-sign">+</h4>
|
||||
|
|
|
|||
|
|
@ -41,8 +41,9 @@
|
|||
$scope.paragraph = null;
|
||||
$scope.originalText = '';
|
||||
$scope.editor = null;
|
||||
$scope.magic = null;
|
||||
|
||||
var editorSetting = {};
|
||||
var pastePercentSign = false;
|
||||
var paragraphScope = $rootScope.$new(true, $rootScope);
|
||||
|
||||
// to keep backward compatibility
|
||||
|
|
@ -300,6 +301,10 @@
|
|||
data, $scope.paragraph.config, $scope.paragraph.settings.params);
|
||||
$scope.originalText = angular.copy(data);
|
||||
$scope.dirtyText = undefined;
|
||||
|
||||
if (editorSetting.editOnDblClick) {
|
||||
closeEditorAndOpenTable();
|
||||
}
|
||||
};
|
||||
|
||||
$scope.saveParagraph = function() {
|
||||
|
|
@ -414,6 +419,28 @@
|
|||
commitParagraph($scope.paragraph.title, $scope.paragraph.text, newConfig, newParams);
|
||||
};
|
||||
|
||||
var openEditorAndCloseTable = function() {
|
||||
console.log('open editor and close output');
|
||||
|
||||
var newParams = angular.copy($scope.paragraph.settings.params);
|
||||
var newConfig = angular.copy($scope.paragraph.config);
|
||||
newConfig.editorHide = false;
|
||||
newConfig.tableHide = true;
|
||||
|
||||
commitParagraph($scope.paragraph.title, $scope.paragraph.text, newConfig, newParams);
|
||||
};
|
||||
|
||||
var closeEditorAndOpenTable = function() {
|
||||
console.log('close editor and open output');
|
||||
|
||||
var newParams = angular.copy($scope.paragraph.settings.params);
|
||||
var newConfig = angular.copy($scope.paragraph.config);
|
||||
newConfig.editorHide = true;
|
||||
newConfig.tableHide = false;
|
||||
|
||||
commitParagraph($scope.paragraph.title, $scope.paragraph.text, newConfig, newParams);
|
||||
};
|
||||
|
||||
$scope.showTitle = function() {
|
||||
var newParams = angular.copy($scope.paragraph.settings.params);
|
||||
var newConfig = angular.copy($scope.paragraph.config);
|
||||
|
|
@ -626,6 +653,12 @@
|
|||
$scope.handleFocus(false);
|
||||
});
|
||||
|
||||
$scope.editor.on('paste', function(e) {
|
||||
if (e.text.startsWith('%')) {
|
||||
pastePercentSign = true;
|
||||
}
|
||||
});
|
||||
|
||||
$scope.editor.getSession().on('change', function(e, editSession) {
|
||||
autoAdjustEditorHeight(_editor.container.id);
|
||||
});
|
||||
|
|
@ -729,37 +762,37 @@
|
|||
// Evaluate the mode only if the the position is undefined
|
||||
// or the first 30 characters of the paragraph have been modified
|
||||
// or cursor position is at beginning of second line.(in case user hit enter after typing %magic)
|
||||
if ((typeof pos === 'undefined') || (pos.row === 0 && pos.column < 30) || (pos.row === 1 && pos.column === 0)) {
|
||||
if ((typeof pos === 'undefined') || (pos.row === 0 && pos.column < 30) ||
|
||||
(pos.row === 1 && pos.column === 0) || pastePercentSign) {
|
||||
// If paragraph loading, use config value if exists
|
||||
if ((typeof pos === 'undefined') && $scope.paragraph.config.editorMode) {
|
||||
session.setMode($scope.paragraph.config.editorMode);
|
||||
} else {
|
||||
var magic;
|
||||
// set editor mode to default interpreter syntax if paragraph text doesn't start with '%'
|
||||
// TODO(mina): dig into the cause what makes interpreterBindings has no element
|
||||
if (!paragraphText.startsWith('%') && ((typeof pos !== 'undefined') && pos.row === 0 && pos.column === 1) ||
|
||||
(typeof pos === 'undefined') && $scope.$parent.interpreterBindings.length !== 0) {
|
||||
magic = $scope.$parent.interpreterBindings[0].name;
|
||||
var magic = getInterpreterName(paragraphText);
|
||||
if (editorSetting.magic !== magic) {
|
||||
editorSetting.magic = magic;
|
||||
getEditorSetting(magic)
|
||||
.then(function(editorSetting) {
|
||||
if (!_.isEmpty(editorSetting.editor)) {
|
||||
setEditorLanguage(session, editorSetting.editor.language);
|
||||
}
|
||||
.then(function(setting) {
|
||||
setEditorLanguage(session, setting.editor.language);
|
||||
_.merge(editorSetting, setting.editor);
|
||||
});
|
||||
} else {
|
||||
var replNameRegexp = /%(.+?)\s/g;
|
||||
var match = replNameRegexp.exec(paragraphText);
|
||||
if (match && $scope.magic !== match[1]) {
|
||||
magic = match[1].trim();
|
||||
$scope.magic = magic;
|
||||
getEditorSetting(magic)
|
||||
.then(function(editorSetting) {
|
||||
setEditorLanguage(session, editorSetting.editor.language);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pastePercentSign = false;
|
||||
};
|
||||
|
||||
var getInterpreterName = function(paragraphText) {
|
||||
var intpNameRegexp = /%(.+?)\s/g;
|
||||
var match = intpNameRegexp.exec(paragraphText);
|
||||
if (match) {
|
||||
return match[1].trim();
|
||||
// get default interpreter name if paragraph text doesn't start with '%'
|
||||
// TODO(mina): dig into the cause what makes interpreterBindings to have no element
|
||||
} else if ($scope.$parent.interpreterBindings.length !== 0) {
|
||||
return $scope.$parent.interpreterBindings[0].name;
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
var autoAdjustEditorHeight = function(id) {
|
||||
|
|
@ -2468,6 +2501,23 @@
|
|||
}
|
||||
});
|
||||
|
||||
$scope.$on('doubleClickParagraph', function(event, paragraphId) {
|
||||
if ($scope.paragraph.id === paragraphId && editorSetting.editOnDblClick) {
|
||||
var deferred = $q.defer();
|
||||
openEditorAndCloseTable();
|
||||
$timeout(
|
||||
$scope.$on('updateParagraph', function(event, data) {
|
||||
deferred.resolve(data);
|
||||
}
|
||||
), 1000);
|
||||
|
||||
deferred.promise.then(function(data) {
|
||||
$scope.editor.focus();
|
||||
$scope.goToEnd();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$scope.$on('runParagraph', function(event) {
|
||||
$scope.runParagraph($scope.editor.getValue());
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1351,7 +1351,8 @@ public class InterpreterFactory implements InterpreterGroupFactory {
|
|||
Interpreter intp = getInterpreter(user, noteId, replName);
|
||||
Map<String, Object> editor = Maps.newHashMap(
|
||||
ImmutableMap.<String, Object>builder()
|
||||
.put("language", "text").build());
|
||||
.put("language", "text")
|
||||
.put("editOnDblClick", "false").build());
|
||||
String defaultSettingName = getDefaultInterpreterSetting(noteId).getName();
|
||||
String group = StringUtils.EMPTY;
|
||||
try {
|
||||
|
|
|
|||
Loading…
Reference in a new issue