CodeMirror Highlight specific Regex-Match - javascript

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
}

Related

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

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.

How to use owl carousel in Nuxt?

I want to make script work on every page without that these page need loaded;
I have owl caroussel script on my static folder, and i already put it in nuxt.config.js, here how i put it:
head: {
title: 'title',
htmlAttrs: {
lang: 'en'
},
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: '' },
{ name: 'format-detection', content: 'telephone=no' }
],
link: [
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.ico' }
],
script: [{
src: process.env.BASE_URL_ROOT + "/jquery-3.3.1.min.js",
type: "text/javascript"
},
{
src: process.env.BASE_URL_ROOT + "/owl.carousel.min.js",
type: "text/javascript"
},
{
src: process.env.BASE_URL_ROOT + "/main-script.js",
type: "text/javascript"
}
]
},
And there is the script on my main-script.js:
$(document).ready(function() {
$('.owl-menu').owlCarousel({
loop: true,
responsiveClass: true,
center: true,
items: 6,
nav: true,
dots: false,
autoWidth: true,
responsive: {
600: {
items: 6,
nav: true,
autoWidth: true,
center: true,
loop: true
},
}
})
$('.owl-video').owlCarousel({
loop: true,
center: true,
items: 3,
margin: 10,
nav: true,
dots: true,
responsive: {
600: {
items: 3,
margin: 12,
},
},
navContainer: "#nav-conte",
navText: [
'<i class="far fa-arrow-alt-circle-left" aria-hidden="true" style="color: rgba(0,0,0,0.67843);"></i>',
'<i class="far fa-arrow-alt-circle-right" aria-hidden="true" style="color: rgba(0,0,0,0.67843);"></i>'
]
})
})
The caroussel work well on the page if the page is loaded, but if it come from nuxt navigation, the caroussel script not work anymore.
Solution that i used is MutationObserver that look at the change on the DOM; on my main-script.js:
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var observer = new MutationObserver(function(mutations, observer) {
// my owl caroussel script
});
observer.observe(document, {
subtree: true,
attributes: true
});
Here, you're using some jQuery code that relies on selecting specific parts of the DOM. Meanwhile, nowadays front-end frameworks do handle the DOM in a different manner and relying more on the state or refs than actual querySelector.
Hence, I do not recommend even trying to wire it. You should probably try and use a Vue package to make the same kind of feature.
It will be probably less heavy (bundle-size), more easy to integrate with your Nuxt app and you will not rely on buggy and hacky behavior.
Check this list of Carousels: https://github.com/vuejs/awesome-vue#carousel
I do use vue-awesome-swiper, more on a heavier side but really complete.
Also, I don't know if you really need to have jQuery in your Nuxt app on top of Vue, but if you want a clean and simple way of installing it into your Nuxt app, you follow my other answer here: https://stackoverflow.com/a/68414170/8816585
EDIT, even owl carousel deprecates itself as you can see
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var observer = new MutationObserver(function(mutations, observer) {
// your owl caroussel script
$('.owl-menu').owlCarousel({
loop: true,
responsiveClass: true,
center: true,
items: 6,
nav: true,
dots: false,
autoWidth: true,
responsive: {
600: {
items: 6,
nav: true,
autoWidth: true,
center: true,
loop: true
},
}
})
$('.owl-video').owlCarousel({
loop: true,
center: true,
items: 3,
margin: 10,
nav: true,
dots: true,
responsive: {
600: {
items: 3,
margin: 12,
},
},
navContainer: "#nav-conte",
navText: [
'<i class="far fa-arrow-alt-circle-left" aria-hidden="true" style="color: rgba(0,0,0,0.67843);"></i>',
'<i class="far fa-arrow-alt-circle-right" aria-hidden="true" style="color: rgba(0,0,0,0.67843);"></i>'
]
})
});
observer.observe(document, {
subtree: true,
attributes: true
});
This worked for me. You can try. enter link description here

Occasionally addMissingImports on save imports React again

I am using typescript and in *.tsx files, especially when i am copying code around, it quite often adds an additional
import React from "react";
// ? On Save
"editor.codeActionsOnSave": {
"source.addMissingImports": true,
"source.fixAll.eslint": true
// "source.organizeImports": true
}
I am using this configuration and works fine.
extensions.json
{
"recommendations": [
"amatiasq.sort-imports",
"dbaeumer.vscode-eslint",
"eamodio.gitlens",
"eg2.vscode-npm-script",
"esbenp.prettier-vscode",
"github.copilot",
"github.vscode-pull-request-github",
"ibm.output-colorizer",
"mhutchie.git-graph",
"ms-azuretools.vscode-docker",
"ms-kubernetes-tools.vscode-kubernetes-tools",
"ms-playwright.playwright",
"ms-vscode-remote.vscode-remote-extensionpack",
"pkief.material-icon-theme",
"quicktype.quicktype",
"redhat.vscode-yaml",
"ryanluker.vscode-coverage-gutters",
"streetsidesoftware.code-spell-checker",
"stylelint.vscode-stylelint",
"tyriar.sort-lines"
]
}
settings.json
{
"[javascript]": {
"editor.formatOnSave": false
},
"[javascriptreact]": {
"editor.formatOnSave": false
},
"[jsonc]": {
"editor.defaultFormatter": "vscode.json-language-features"
},
"[typescript]": {
"editor.formatOnSave": false
},
"[typescriptreact]": {
"editor.formatOnSave": false
},
"diffEditor.ignoreTrimWhitespace": false,
"editor.bracketPairColorization.enabled": true,
"editor.codeActionsOnSave": {
"source.addMissingImports": true,
"source.fixAll": false,
"source.fixAll.eslint": true,
"source.organizeImports": false
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.guides.bracketPairs": "active",
"editor.inlineSuggest.enabled": true,
"editor.suggestSelection": "first",
"editor.tabSize": 2,
"eslint.alwaysShowStatus": true,
"eslint.format.enable": true,
"eslint.probe": [
"html",
"javascript",
"javascriptreact",
"markdown",
"typescript",
"typescriptreact"
],
"files.watcherExclude": {
"**/*.pem": true,
"**/*.tsbuildinfo": true,
"**/.DS_Store": true,
"**/.env.development.local": true,
"**/.env.local": true,
"**/.env.production.local": true,
"**/.env.test.local": true,
"**/.next/**": true,
"**/.pnp.js": true,
"**/.pnp/**": true,
"**/.vercel": true,
"**/build/**": true,
"**/coverage/**": true,
"**/node_modules/**": true,
"**/npm-debug.log*": true,
"**/out/**": true,
"**/yarn-debug.log*": true,
"**/yarn-error.log*": true
},
"github.copilot.enable": {
"*": true,
"markdown": false,
"plaintext": true,
"yaml": true
},
"redhat.telemetry.enabled": true,
"sort-imports.ignore-type-defs": false,
"stylelint.validate": [
"css",
"scss"
],
"terminal.integrated.sendKeybindingsToShell": true,
"window.zoomLevel": 1,
"workbench.iconTheme": "material-icon-theme"
}

codemirror show hints with angular

How to show hints and define dictionary with ui-codemirror?
$scope.cmOption = {
lineWrapping : true,
lineNumbers: true,
textWrapping: true,
indentWithTabs: true,
readOnly: false,
mode: "javascript",
matchBrackets: true,
autoCloseBrackets: true,
gutters: ["CodeMirror-lint-markers"],
lint: true,
showHint: true
};
I tried with ng-codemirror-dictionary-hint but it gives me an error
instance.showHint is not a function

Jqgrid search option for local datatype not working

I want to add search option for my jqgrid table,
$('#jqgrid').jqGrid({
datatype: 'local',
data: mydata,
caption: 'Titlepage Parameters',
gridview: true,
height: 'auto',
colNames: ['title', 'color', 'fontsize'],
colModel: [
{name: 'config.titlepage.title' },
{name: 'config.titlepage.color' },
{name: 'config.titlepage.fontsize' },
],
pager: '#pageGrid'
localReader: {
id: "_id.$oid"
}
});
$('#jqgrid').jqGrid('navGrid', "#pageGrid",
{ search: true, edit: false, add: false, del: false, refresh: false }, {}, {},
{ recreateFilter: true, overlay: true, multipleSearch: true, multipleGroup: true});
I'm getting the search option but when I enter the search string and click on Filter button, search is happening.
Please help me here, do I need add any library files to perform for this search filter?
I'm not sure which problem with searching you have. The only clear error is: you skip one {} in the list of navGrid. You current option of navGrid set delete options as searching options. Correct option will be
$('#jqgrid').jqGrid('navGrid', "#pageGrid",
{ search: true, edit: false, add: false, del: false, refresh: false }, {}, {}, {},
{ recreateFilter: true, overlay: true, multipleSearch: true, multipleGroup: true});
Additionally you can consider to add ignoreCase: true option to the grid to make searching case insensitive. The demo seems to work correctly.
Another option which you can use to read the same data: to use datatype: 'jsonstring'. In the case you can use jsonmap and choose more readable name property. In the case the internal data of grid will contains only the data which you need. The demo demonstrate this approach. It uses the following code
var mydata = [
{
"_id": {"$oid": "50a3f962b7718da1a3090fa9"},
"config": { "titlepage": { "title": "My First Title", "color": true,
"fontsize": "42/44" } } }
];
$('#jqgrid').jqGrid({
datatype: 'jsonstring',
datastr: mydata,
caption: 'Titlepage Parameters',
gridview: true,
height: 'auto',
colModel: [
{name: 'title', jsonmap: "config.titlepage.title" },
{name: 'color', jsonmap: "config.titlepage.color" },
{name: 'fontsize', jsonmap: "config.titlepage.fontsize" },
],
pager: '#pageGrid',
jsonReader: {
repeatitems: false,
id: "_id.$oid"
}
});
$('#jqgrid').jqGrid('navGrid', "#pageGrid",
{ search: true, edit: false, add: false, del: false, refresh: false }, {}, {}, {},
{ recreateFilter: true, overlay: true, multipleSearch: true, multipleGroup: true});
In any way I don't see any problem with searching in both demos.

Categories

Resources