How can enable/disable auto complete options for ACE editor? - javascript

I'd like to enable/disable autocomplete options of the ACE editor by pressing the keys 'ctrl+spacebar'.
Below mentioned is my code which I am using
highlightEditor(editor, codeEditorElmRef) {
const element = codeEditorElmRef;
const editorOptions: Partial<ace.Ace.EditorOptions> = {
highlightActiveLine: true,
showLineNumbers: true,
highlightSelectedWord: true,
fontSize: 12,
tabSize: 2
};
const codeEditor: ace.Ace.Editor = ace.edit(element, editorOptions);
codeEditor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true
});
console.log("153 else statement")
codeEditor.setOptions({
enableBasicAutocompletion: false,
enableSnippets: false,
enableLiveAutocompletion: false
let currentObj = this;
// key bindings to ace editor
codeEditor.commands.addCommand({
name: 'turn-on/off',
bindKey: { win: "Ctrl-space", mac: "Cmd-space" },
exec: function (editor) {
currentObj.highlightEditor(editor, codeEditorElmRef);
}
});
editor.editorID = codeEditor.id;
codeEditor.resize(true);
this.aceCodeEditors.push(codeEditor);
}
Please help me in this.

Related

How to replace strings in CodeMirror

https://codemirror.net/5/doc/manual.html
I need to replace a string with another oninput:
const editor = CodeMirror.fromTextArea(document.getElementById("editor"), {
lineNumbers: true,
tabSize: 2,
mode: "simplemode", // some regex stuff to highlight
htmlMode: true,
highlightSelectionMatches: {
minChars: 2,
showToken: "string",
style: "matchhighlight",
},
});
editor.on("change", function () {
let text = editor.getValue();
edit the text, for example
text = text.replace(/abc/g, "");
editor.setValue(text);
});
editor.refresh();
The editor.on("change",... makes my textarea field freeze on the first key press. I have no other idea how to replace strings in my CodeMirror on keypress.

Google Sheets / Apps Script: Function to create a new spreadsheet in specific folder

How to create a new spreadsheet within a specific folder?
I am using the following function to take data from one sheet, validate it and save it in another sheet if it isn't already there.
Additionally I want to create a completely new Spreadsheet in a specific folder, use the data from B8 as its name and fill it with the same data. How do I do that?
function validateEntry()
{
var myGooglSheet = SpreadsheetApp.getActiveSpreadsheet();
var shUserForm = myGooglSheet.getSheetByName("Fahrzeug anlegen");
var ui = SpreadsheetApp.getUi();
shUserForm.getRange("B4").setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
shUserForm.getRange("B8").setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
shUserForm.getRange("B11").setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
shUserForm.getRange("B14").setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
shUserForm.getRange("B17").setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
shUserForm.getRange("B20").setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
shUserForm.getRange("D8").setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
shUserForm.getRange("D11").setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
shUserForm.getRange("D14").setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
shUserForm.getRange("D17").setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
shUserForm.getRange("D20").setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
if(shUserForm.getRange("B8").isBlank() == true)
{
ui.alert("Fahrzeugnummer eingeben!");
shUserForm.getRange("B8").activate();
shUserForm.getRange("B8").setBackground('#FF0000');
return false;
}
else if(shUserForm.getRange("B11").isBlank() == true)
{
ui.alert("Fahrgestellnummer eingeben!");
shUserForm.getRange("B11").activate();
shUserForm.getRange("B11").setBackground('#FF0000');
return false;
}
else if(shUserForm.getRange("B14").isBlank() == true)
{
ui.alert("Marke eingeben!");
shUserForm.getRange("B14").activate();
shUserForm.getRange("B14").setBackground('#FF0000');
return false;
}
else if(shUserForm.getRange("B17").isBlank() == true)
{
ui.alert("Modell eingeben!");
shUserForm.getRange("B17").activate();
shUserForm.getRange("B17").setBackground('#FF0000');
return false;
}
else if(shUserForm.getRange("B20").isBlank() == true)
{
ui.alert("Kennzeichen eingeben!");
shUserForm.getRange("B20").activate();
shUserForm.getRange("B20").setBackground('#FF0000');
return false;
}
else if(shUserForm.getRange("D8").isBlank() == true)
{
ui.alert("EK-Datum eingeben!");
shUserForm.getRange("D8").activate();
shUserForm.getRange("D8").setBackground('#FF0000');
return false;
}
else if(shUserForm.getRange("D11").isBlank() == true)
{
ui.alert("EK-Preis eingeben!");
shUserForm.getRange("D11").activate();
shUserForm.getRange("D11").setBackground('#FF0000');
return false;
}
else if(shUserForm.getRange("D14").isBlank() == true)
{
ui.alert("Steuer eingeben!");
shUserForm.getRange("D14").activate();
shUserForm.getRange("D14").setBackground('#FF0000');
return false;
}
else if(shUserForm.getRange("D17").isBlank() == true)
{
ui.alert("Inzahlung eingeben!");
shUserForm.getRange("D17").activate();
shUserForm.getRange("D17").setBackground('#FF0000');
return false;
}
else if(shUserForm.getRange("D20").isBlank() == true)
{
ui.alert("Art eingeben!");
shUserForm.getRange("D20").activate();
shUserForm.getRange("D20").setBackground('#FF0000');
return false;
}
return true;
}
function submitData()
{
var myGooglSheet = SpreadsheetApp.getActiveSpreadsheet();
var shUserForm = myGooglSheet.getSheetByName("Fahrzeug anlegen");
var datasheet = myGooglSheet.getSheetByName("Masterliste");
var str = shUserForm.getRange("B8").getValue();
var values = datasheet.getDataRange().getValues();
var valuesFound = false;
for (var i = 0; i < values.length; i++)
{
var rowValue = values[i];
if (rowValue[0] == str)
{
shUserForm.getRange("B8").setValue(rowValue[0]).setFontFamily("Courier New").setFontSize(12).setHorizontalAlignment('left');
shUserForm.getRange("B11").setValue(rowValue[1]).setFontFamily("Courier New").setFontSize(12).setHorizontalAlignment('left');
shUserForm.getRange("B14").setValue(rowValue[2]).setFontFamily("Courier New").setFontSize(12).setHorizontalAlignment('left');
shUserForm.getRange("B17").setValue(rowValue[3]).setFontFamily("Courier New").setFontSize(12).setHorizontalAlignment('left');
shUserForm.getRange("B20").setValue(rowValue[4]).setFontFamily("Courier New").setFontSize(12).setHorizontalAlignment('left');
shUserForm.getRange("D8").setValue(rowValue[5]).setFontFamily("Courier New").setFontSize(12).setHorizontalAlignment('left');
shUserForm.getRange("D11").setValue(rowValue[7]).setFontFamily("Courier New").setFontSize(12).setHorizontalAlignment('left');
shUserForm.getRange("D14").setValue(rowValue[8]).setFontFamily("Courier New").setFontSize(12).setHorizontalAlignment('left');
shUserForm.getRange("D17").setValue(rowValue[9]).setFontFamily("Courier New").setFontSize(12).setHorizontalAlignment('left');
shUserForm.getRange("D20").setValue(rowValue[10]).setFontFamily("Courier New").setFontSize(12).setHorizontalAlignment('left');
var ui = SpreadsheetApp.getUi();
ui.alert("Eintrag schon vorhanden!");
return;
}
}
if(valuesFound == false)
{
var ui = SpreadsheetApp.getUi();
var response = ui.alert("Speichern", 'Daten speichern?',ui.ButtonSet.YES_NO);
if (response == ui.Button.NO)
{
return;
}
if (validateEntry() == true)
{
var blankRow = datasheet.getLastRow()+1; // nächste leere Zeile finden
datasheet.getRange(blankRow, 1).setValue(shUserForm.getRange("B8").getValue());
datasheet.getRange(blankRow, 2).setValue(shUserForm.getRange("B11").getValue());
datasheet.getRange(blankRow, 3).setValue(shUserForm.getRange("B14").getValue());
datasheet.getRange(blankRow, 4).setValue(shUserForm.getRange("B17").getValue());
datasheet.getRange(blankRow, 5).setValue(shUserForm.getRange("B20").getValue());
datasheet.getRange(blankRow, 6).setValue(shUserForm.getRange("D8").getValue());
datasheet.getRange(blankRow, 8).setValue(shUserForm.getRange("D11").getValue());
datasheet.getRange(blankRow, 9).setValue(shUserForm.getRange("D14").getValue());
datasheet.getRange(blankRow, 10).setValue(shUserForm.getRange("D17").getValue());
datasheet.getRange(blankRow, 11).setValue(shUserForm.getRange("D20").getValue());
ui.alert(' "Neues Fahrzeug gespeichert: #'+ shUserForm.getRange("B8").getValue() +'" ');
shUserForm.getRange("B4").clear().setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
shUserForm.getRange("B8").clear().setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
shUserForm.getRange("B11").clear().setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
shUserForm.getRange("B14").clear().setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
shUserForm.getRange("B17").clear().setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
shUserForm.getRange("B20").clear().setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
shUserForm.getRange("D8").clear().setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
shUserForm.getRange("D11").clear().setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
shUserForm.getRange("D14").clear().setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
shUserForm.getRange("D17").clear().setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
shUserForm.getRange("D20").clear().setBackground('#FFFFFF').setBorder(true, true, true, true, false, false, '#d9d9d9', SpreadsheetApp.BorderStyle.SOLID);
}
}
else
{
ui.alert("Eintrag schon vorhanden!");
ui.alert("Kein Eintrag gefunden!");
}
}
EDITED: You asked about creating a new spreadsheet in a specific folder, named with data from specific cell.
This function does that. It takes the desired filename as an input, so you can just call it from within one of your other functions and pass the value of cell B8 as the desired name.
function newSpreadsheet(name){
var destination = DriveApp.getFolderById('[FOLDER ID]')
var newFile = SpreadsheetApp.create(name).getId()
destination.addFile(DriveApp.getFileById(newFile))
}
Breakdown
var destination sets the target folder for the new file. You will need to put the desired folder location into the script, which you can get from the URL of the folder.
var newFile creates a new Google Sheet, naming it with the name you pass to this function. It returns the ID of the new file.
destination.addFile moves the new file into the destination folder.

CodeMirror Highlight specific Regex-Match

I'm trying to highlight all %()% substrings in the htmlmixed mode. The matching RegExp is ([%(](.*)[)%]).
Here's the code i'm using for CodeMirror:
const code = CodeMirror.fromTextArea(document.querySelector("#id"), {
theme: "dracula",
mode: "text/html",
lineNumbers: true,
firstLineNumber: 1,
spellcheck: false,
autocorrect: true,
extraKeys: { "Ctrl-Space": "autocomplete" },
styleActiveLine: true,
highlightSelectionMatches: { showToken: /\w/, annotateScrollbar: true }
});
Thanks
You have to add a style property in highlightSelectionMatches.
const code = CodeMirror.fromTextArea(document.querySelector("#id"), {
theme: "dracula",
mode: "text/html",
lineNumbers: true,
firstLineNumber: 1,
spellcheck: false,
autocorrect: true,
extraKeys: { "Ctrl-Space": "autocomplete" },
styleActiveLine: true,
highlightSelectionMatches: {
minChars: 2,
showToken: /\w/,
style:'matchhighlight',
annotateScrollbar: true
}
});
Add below in css:
.cm-matchhighlight {
background: red !important
}

changing tab space in atom-typescript

Atom-typescript changes tab space from 2 to 4 when we format the code.
I changed formatting.js file and set it to 2 but still i'm facing the same issue..
How can i change the tab space in atom-typescript?
below is the content of formatting.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Maintainance:
* When a new option is added add it to:
* - the FormatCodeOptions interface
* - the defaultFormatCodeOptions function
* - the makeFormatCodeOptions function
*/
const os_1 = require("os");
function defaultFormatCodeOptions() {
return {
baseIndentSize: 2,
indentSize: 2,
tabSize: 2,
newLineCharacter: os_1.EOL,
convertTabsToSpaces: true,
indentStyle: "Smart",
insertSpaceAfterCommaDelimiter: true,
insertSpaceAfterSemicolonInForStatements: true,
insertSpaceBeforeAndAfterBinaryOperators: true,
insertSpaceAfterKeywordsInControlFlowStatements: true,
insertSpaceAfterFunctionKeywordForAnonymousFunctions: false,
insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: false,
insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: false,
insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: false,
insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: false,
placeOpenBraceOnNewLineForFunctions: false,
placeOpenBraceOnNewLineForControlBlocks: false,
};
}
exports.defaultFormatCodeOptions = defaultFormatCodeOptions;
//# sourceMappingURL=formatting.js.map
As suggested by #baruch, here is the reference: github.com/TypeStrong/atom-typescript/issues/1236
I'm posting what worked for me.
To change indentation to 2 for atom-typescript:
Go to your project directory.
Open or create tsconfig.json.
Add the following code
"formatCodeOptions": {
"baseIndentSize": 0,
"indentSize": 2,
"tabSize": 2,
"newLineCharacter": "\n",
"convertTabsToSpaces": true,
"indentStyle": "Smart",
"insertSpaceAfterCommaDelimiter": true,
"insertSpaceAfterSemicolonInForStatements": false,
"insertSpaceBeforeAndAfterBinaryOperators": true,
"insertSpaceAfterConstructor": false,
"insertSpaceAfterKeywordsInControlFlowStatements": true,
"insertSpaceAfterFunctionKeywordForAnonymousFunctions": false,
"insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis": false,
"insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false,
"insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false,
"insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces": false,
"insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces": false,
"insertSpaceBeforeFunctionParenthesis": false,
"placeOpenBraceOnNewLineForFunctions": false,
"placeOpenBraceOnNewLineForControlBlocks": false
}
This worked for me!

Object doesn't support property or method 'jqGrid' on windows server 2012

the jq grid is running fine on asp.net dev server but on IIS 8 (Windows Server 2012) it is giving the following error: Object doesn't support property or method 'jqGrid'
JS
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery('#GridList').jqGrid({
autoencode: true,
autowidth: true,
caption: 'List',
cmTemplate: { sortable: false },
datatype: 'json',
jsonReader: { 'repeatitems': false, 'id': 'Id' },
emptyrecords: 'No record Found',
multiselect: true,
gridview: true,
recordpos: 'left',
height: '100%',
loadui: 'block',
pager: '#pager',
rowList: [10, 15, 20, 50],
rowNum: 10,
viewsortcols: [true, 'vertical', true],
shrinkToFit: true,
url: '#Url.Action("List")',
viewrecords: true,
width: '650',
colModel: [
#Html.GetGridColumn(model => model.Id),
#Html.GetGridColumn(model => model.ResultId),
#Html.GetGridColumn(model => model.HostReference),
#Html.GetGridColumn(model => model.FirstName),
#Html.GetGridColumn(model => model.LastName),
#Html.GetGridColumn(model => model.UserID)
]
});
//jQuery('#GridList').jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false });
jQuery("#GridList").navGrid('#pager', { edit: false, add: false, del: false });
jQuery("#btnSubmit").click(function () {
var s;
s = jQuery("#GridList").jqGrid('getGridParam', 'selarrrow');
alert(s);
});
});
</script>
Update:
this is how i call the list:
protected ActionResult List(GridSettings grid)
{
var query = ListQuery.AsQueryable().OrderBy(grid.SortColumn, grid.SortOrder);
if (grid.IsSearch && grid.Where != null && grid.Where.rules != null)
{
query = grid.Where.rules.Aggregate(query,
(current, rule) => current.Where(rule.field, rule.data, rule.op));
}
var count = query.Count();
var data = query.Skip((grid.PageIndex - 1) * grid.PageSize)
.Take(grid.PageSize)
.Select(Mapper.Map<TModel, TListModel>);
// TO DO: Prevent GridDataType.NoDisplay fields from being
// serialised
var result = new
{
total = (int)Math.Ceiling((double)count / grid.PageSize),
page = grid.PageIndex,
records = count,
rows = data.ToArray()
};
var serialiser = new JavaScriptSerializer();
serialiser.MaxJsonLength = int.MaxValue;
//serialiser.RegisterConverters(new[] { new SingleSelectConverter() });
//serialiser.RegisterConverters(new[] { new MultiSelectConverter() });
var jsonString = serialiser.Serialize(result);
return new ContentResult { Content = jsonString, ContentType = "application/json"};
}
What seems that you have issue of reference, just check the jqgrid library path whether that is referenced properly or not.
or may be you could have forgot to reference the library with all other required library.
some side notes:
Since you are using dataType:"json" and i can see that you have not used loadonce: true option in the list which is required when dataType is "json" and you have mentioned your column names, try including those too.:
jQuery('#GridList').jqGrid({
autoencode: true,
autowidth: true,
caption: 'List',
cmTemplate: { sortable: false },
datatype: 'json',
........
loadonce: true
});
Finally i found my answer, i was using third party dll, it's in dll folder, when i depolyed, i had to add to bin folder as well...Thank you for the help

Categories

Resources