share syntax highlighting selection with peers
This commit is contained in:
parent
2d5caf38d9
commit
deb63d2447
@ -150,6 +150,9 @@ define([
|
|||||||
// append the userlist to the hyperjson structure
|
// append the userlist to the hyperjson structure
|
||||||
obj.metadata = userList;
|
obj.metadata = userList;
|
||||||
|
|
||||||
|
// set mode too...
|
||||||
|
obj.highlightMode = module.highlightMode;
|
||||||
|
|
||||||
// stringify the json and send it into chainpad
|
// stringify the json and send it into chainpad
|
||||||
var shjson = stringify(obj);
|
var shjson = stringify(obj);
|
||||||
|
|
||||||
@ -370,37 +373,25 @@ define([
|
|||||||
});
|
});
|
||||||
$rightside.append($forgetPad);
|
$rightside.append($forgetPad);
|
||||||
|
|
||||||
// TODO use cb
|
|
||||||
var configureLanguage = function (cb) {
|
var configureLanguage = function (cb) {
|
||||||
// FIXME this is async so make it happen as early as possible
|
// FIXME this is async so make it happen as early as possible
|
||||||
Cryptpad.getPadAttribute('language', function (err, lastLanguage) {
|
|
||||||
if (err) {
|
|
||||||
console.log("Unable to get pad language");
|
|
||||||
}
|
|
||||||
|
|
||||||
lastLanguage = lastLanguage || 'javascript';
|
|
||||||
|
|
||||||
/* Let the user select different syntax highlighting modes */
|
/* Let the user select different syntax highlighting modes */
|
||||||
var syntaxDropdown = '<select title="syntax highlighting" id="language-mode">\n' +
|
var $language = module.$language = $('<select>', {
|
||||||
|
title: 'syntax highlighting',
|
||||||
|
id: 'language-mode',
|
||||||
|
}).on('change', function () {
|
||||||
|
setMode($language.val());
|
||||||
|
onLocal();
|
||||||
|
});
|
||||||
|
|
||||||
Modes.list.map(function (o) {
|
Modes.list.map(function (o) {
|
||||||
var selected = o.mode === lastLanguage? ' selected="selected"' : '';
|
$language.append($('<option>', {
|
||||||
return '<option value="' + o.mode + '"'+selected+'>' + o.language + '</option>';
|
value: o.mode,
|
||||||
}).join('\n') +
|
}).text(o.language));
|
||||||
'</select>';
|
|
||||||
|
|
||||||
setMode(lastLanguage);
|
|
||||||
|
|
||||||
$rightside.append(syntaxDropdown);
|
|
||||||
|
|
||||||
var $language = module.$language = $bar.find('#language-mode').on('change', function () {
|
|
||||||
var mode = $language.val();
|
|
||||||
setMode(mode);
|
|
||||||
Cryptpad.setPadAttribute('language', mode, function (err, data) {
|
|
||||||
// TODO
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
$rightside.append($language);
|
||||||
cb();
|
cb();
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -495,6 +486,15 @@ define([
|
|||||||
if(userDoc !== "") {
|
if(userDoc !== "") {
|
||||||
var hjson = JSON.parse(userDoc);
|
var hjson = JSON.parse(userDoc);
|
||||||
newDoc = hjson.content;
|
newDoc = hjson.content;
|
||||||
|
|
||||||
|
if (hjson.highlightMode) {
|
||||||
|
setMode(hjson.highlightMode, module.$language);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!module.highlightMode) {
|
||||||
|
setMode('javascript', module.$language);
|
||||||
|
console.log("%s => %s", module.highlightMode, module.$language.val());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the user list (metadata) from the hyperjson
|
// Update the user list (metadata) from the hyperjson
|
||||||
@ -565,6 +565,11 @@ define([
|
|||||||
var hjson = JSON.parse(shjson);
|
var hjson = JSON.parse(shjson);
|
||||||
var remoteDoc = hjson.content;
|
var remoteDoc = hjson.content;
|
||||||
|
|
||||||
|
var highlightMode = hjson.highlightMode;
|
||||||
|
if (highlightMode && highlightMode !== module.highlightMode) {
|
||||||
|
setMode(highlightMode, module.$language);
|
||||||
|
}
|
||||||
|
|
||||||
//get old cursor here
|
//get old cursor here
|
||||||
var oldCursor = {};
|
var oldCursor = {};
|
||||||
oldCursor.selectionStart = cursorToPos(editor.getCursor('from'), oldDoc);
|
oldCursor.selectionStart = cursorToPos(editor.getCursor('from'), oldDoc);
|
||||||
@ -590,11 +595,13 @@ define([
|
|||||||
var localDoc = canonicalize($textarea.val());
|
var localDoc = canonicalize($textarea.val());
|
||||||
var hjson2 = {
|
var hjson2 = {
|
||||||
content: localDoc,
|
content: localDoc,
|
||||||
metadata: userList
|
metadata: userList,
|
||||||
|
highlightMode: highlightMode,
|
||||||
};
|
};
|
||||||
var shjson2 = stringify(hjson2);
|
var shjson2 = stringify(hjson2);
|
||||||
if (shjson2 !== shjson) {
|
if (shjson2 !== shjson) {
|
||||||
console.error("shjson2 !== shjson");
|
console.error("shjson2 !== shjson");
|
||||||
|
TextPatcher.log(shjson, TextPatcher.diff(shjson, shjson2));
|
||||||
module.patchText(shjson2);
|
module.patchText(shjson2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user