mirror of
https://github.com/gristlabs/grist-core.git
synced 2026-03-02 04:09:24 +00:00
(core) Readonly editors
Summary: Grist should not prevent read-only viewers from opening cell editors since they usually provide much more information than is visible in a cell. Every editor was enhanced with a read-only mode that provides the same information available for an editor but doesn't allow to change the underlying data. Test Plan: Browser tests Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D2842
This commit is contained in:
@@ -26,6 +26,7 @@ function AceEditor(options) {
|
||||
this.calcSize = (options && options.calcSize) || ((elem, size) => size);
|
||||
this.gristDoc = (options && options.gristDoc) || null;
|
||||
this.editorState = (options && options.editorState) || null;
|
||||
this._readonly = options.readonly || false;
|
||||
|
||||
this.editor = null;
|
||||
this.editorDom = null;
|
||||
@@ -112,6 +113,11 @@ AceEditor.prototype.attachCommandGroup = function(commandGroup) {
|
||||
_.each(commandGroup.knownKeys, (command, key) => {
|
||||
this.editor.commands.addCommand({
|
||||
name: command,
|
||||
// We are setting readonly as true to enable all commands
|
||||
// in a readonly mode.
|
||||
// Because FieldEditor in readonly mode will rewire all commands that
|
||||
// modify state, we are safe to enable them.
|
||||
readOnly: this._readonly,
|
||||
bindKey: {
|
||||
win: key,
|
||||
mac: key,
|
||||
|
||||
@@ -278,16 +278,12 @@ BaseView.prototype.activateEditorAtCursor = function(options) {
|
||||
// LazyArrayModel row model which is also used to build the cell dom. Needed since
|
||||
// it may be used as a key to retrieve the cell dom, which is useful for editor placement.
|
||||
var lazyRow = this.getRenderedRowModel(rowId);
|
||||
if (builder.field.disableEditData() || this.gristDoc.isReadonly.get()) {
|
||||
builder.flashCursorReadOnly(lazyRow);
|
||||
} else {
|
||||
if (!lazyRow) {
|
||||
// TODO scroll into view. For now, just don't activate the editor.
|
||||
return;
|
||||
}
|
||||
this.editRowModel.assign(rowId);
|
||||
builder.buildEditorDom(this.editRowModel, lazyRow, options || {});
|
||||
if (!lazyRow) {
|
||||
// TODO scroll into view. For now, just don't activate the editor.
|
||||
return;
|
||||
}
|
||||
this.editRowModel.assign(rowId);
|
||||
builder.buildEditorDom(this.editRowModel, lazyRow, options || {});
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -58,6 +58,9 @@ export class EditorMonitor extends Disposable {
|
||||
// will be invoked only once
|
||||
let executed = false;
|
||||
|
||||
// don't restore on readonly mode
|
||||
if (doc.isReadonly.get()) { return; }
|
||||
|
||||
// on view shown
|
||||
this._currentViewListener.autoDispose(doc.currentView.addListener(async view => {
|
||||
if (executed) {
|
||||
|
||||
Reference in New Issue
Block a user