Skip to content

Commit

Permalink
Merge pull request #5162 from ajaxorg/small-fixes
Browse files Browse the repository at this point in the history
Small fixes
  • Loading branch information
nightwing authored May 12, 2023
2 parents e30622d + 9373ddf commit 64c7758
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
19 changes: 9 additions & 10 deletions demo/kitchen-sink/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ var layout = require("./layout");
var util = require("./util");
var saveOption = util.saveOption;


var ElasticTabstopsLite = require("ace/ext/elastic_tabstops_lite").ElasticTabstopsLite;

var IncrementalSearch = require("ace/incremental_search").IncrementalSearch;
require("ace/ext/elastic_tabstops_lite");
require("ace/incremental_search");

var TokenTooltip = require("./token_tooltip").TokenTooltip;
require("ace/config").defineOptions(Editor.prototype, "editor", {
Expand Down Expand Up @@ -84,9 +82,9 @@ var MarkerGroup = require("ace/marker_group").MarkerGroup;
var docTooltip = new HoverTooltip();
function loadLanguageProvider(editor) {
require([
"https://www.unpkg.com/ace-linters/build/ace-linters.js"
"https://mkslanc.github.io/ace-linters/build/ace-linters.js"
], function(m) {
var languageProvider = m.LanguageProvider.fromCdn("https://www.unpkg.com/ace-linters/build", {
var languageProvider = m.LanguageProvider.fromCdn("https://mkslanc.github.io/ace-linters/build", {
functionality: {
hover: true,
completion: {
Expand Down Expand Up @@ -138,7 +136,6 @@ function loadLanguageProvider(editor) {
function showAnnotations(session, diagnostics) {
session.clearAnnotations();
let annotations = diagnostics.map((el) => {
console.log(el.severity, el)
return {
row: el.range.start.line,
column: el.range.start.character,
Expand Down Expand Up @@ -170,11 +167,13 @@ function loadLanguageProvider(editor) {

languageProvider.doHover(session, docPos, function(hover) {
var errorMarker = session.state?.diagnosticMarkers.getMarkerAtPosition(docPos);

if (!errorMarker && !hover.content) return;

var range = hover?.range || errorMarker?.range;
if (!range) return;
var hoverNode = hover && dom.buildDom(["div", {}])
range = range ? Range.fromPoints(range.start, range.end) : session.getWordRange(docPos.row, docPos.column);
var hoverNode = hover && dom.buildDom(["div", {}]);
if (hoverNode) {
hover.content.text = hover.content.text.replace(/(?!^)`{3}/gm, "\n$&");
// todo render markdown using ace markdown mode
hoverNode.innerHTML = languageProvider.getTooltipText(hover);
};
Expand Down
6 changes: 3 additions & 3 deletions src/autocomplete/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class AcePopup {
}
addToken(caption.slice(lastIndex, caption.length), "");

tokens.push({type: "completion-spacer", value: " "});
if (data.meta)
tokens.push({type: "completion-meta", value: data.meta});
if (data.message)
Expand Down Expand Up @@ -237,7 +238,7 @@ class AcePopup {
return selectionMarker.start.row;
};
popup.setRow = function(line) {
line = Math.max(this.autoSelect ? 0 : -1, Math.min(this.data.length, line));
line = Math.max(this.autoSelect ? 0 : -1, Math.min(this.data.length - 1, line));
if (selectionMarker.start.row != line) {
popup.selection.clearSelection();
selectionMarker.start.row = selectionMarker.end.row = line || 0;
Expand Down Expand Up @@ -442,9 +443,8 @@ dom.importCssString(`
.ace_autocomplete_right .ace_line {
display: flex;
}
.ace_autocomplete_right .ace_completion-meta {
.ace_autocomplete_right .ace_completion-spacer {
flex: 1;
text-align: right;
}
`, "autocompletion.css", false);

Expand Down
11 changes: 6 additions & 5 deletions src/autocomplete_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ if (typeof process !== "undefined") {
"use strict";

var sendKey = require("./test/user").type;
var {buildDom} = require("./lib/dom");
var ace = require("./ace");
var assert = require("./test/assertions");
var user = require("./test/user");
Expand Down Expand Up @@ -36,16 +37,16 @@ module.exports = {
assert.ok(!editor.container.querySelector("style"));

sendKey("a");
checkInnerHTML('<d "ace_line ace_selected" id="suggest-aria-id:0" role="option" aria-label="arraysort" aria-setsize="2" aria-posinset="0"><s "ace_completion-highlight">a</s><s "ace_">rraysort</s><s "ace_completion-meta">local</s></d><d "ace_line"><s "ace_completion-highlight">a</s><s "ace_">looooooooooooooooooooooooooooong_word</s><s "ace_completion-meta">local</s></d>', function() {
checkInnerHTML('<d "ace_line ace_selected" id="suggest-aria-id:0" role="option" aria-label="arraysort" aria-setsize="2" aria-posinset="0"><s "ace_completion-highlight">a</s><s "ace_">rraysort</s><s "ace_completion-spacer"> </s><s "ace_completion-meta">local</s></d><d "ace_line"><s "ace_completion-highlight">a</s><s "ace_">looooooooooooooooooooooooooooong_word</s><s "ace_completion-spacer"> </s><s "ace_completion-meta">local</s></d>', function() {
sendKey("rr");
checkInnerHTML('<d "ace_line ace_selected" id="suggest-aria-id:0" role="option" aria-label="arraysort" aria-setsize="1" aria-posinset="0"><s "ace_completion-highlight">arr</s><s "ace_">aysort</s><s "ace_completion-meta">local</s></d>', function() {
checkInnerHTML('<d "ace_line ace_selected" id="suggest-aria-id:0" role="option" aria-label="arraysort" aria-setsize="1" aria-posinset="0"><s "ace_completion-highlight">arr</s><s "ace_">aysort</s><s "ace_completion-spacer"> </s><s "ace_completion-meta">local</s></d>', function() {
sendKey("r");
checkInnerHTML('<d "ace_line ace_selected" id="suggest-aria-id:0" role="option" aria-label="arraysort" aria-setsize="1" aria-posinset="0"><s "ace_completion-highlight">arr</s><s "ace_">ayso</s><s "ace_completion-highlight">r</s><s "ace_">t</s><s "ace_completion-meta">local</s></d>', function() {
checkInnerHTML('<d "ace_line ace_selected" id="suggest-aria-id:0" role="option" aria-label="arraysort" aria-setsize="1" aria-posinset="0"><s "ace_completion-highlight">arr</s><s "ace_">ayso</s><s "ace_completion-highlight">r</s><s "ace_">t</s><s "ace_completion-spacer"> </s><s "ace_completion-meta">local</s></d>', function() {

sendKey("Return");
assert.equal(editor.getValue(), "arraysort\narraysort alooooooooooooooooooooooooooooong_word");
editor.execCommand("insertstring", " looooooooooooooooooooooooooooong_");
checkInnerHTML('<d "ace_line ace_selected" id="suggest-aria-id:0" role="option" aria-label="alooooooooooooooooooooooooooooong_word" aria-setsize="1" aria-posinset="0"><s "ace_">a</s><s "ace_completion-highlight">looooooooooooooooooooooooooooong_</s><s "ace_">word</s><s "ace_completion-meta">local</s></d>', function() {
checkInnerHTML('<d "ace_line ace_selected" id="suggest-aria-id:0" role="option" aria-label="alooooooooooooooooooooooooooooong_word" aria-setsize="1" aria-posinset="0"><s "ace_">a</s><s "ace_completion-highlight">looooooooooooooooooooooooooooong_</s><s "ace_">word</s><s "ace_completion-spacer"> </s><s "ace_completion-meta">local</s></d>', function() {
sendKey("Return");
editor.destroy();
editor.container.remove();
Expand Down Expand Up @@ -232,7 +233,7 @@ module.exports = {
assert.equal(editor.completer.popup.renderer.scrollTop, 0);
editor.completer.popup.renderer.$loop._flush();
assert.equal(editor.completer.popup.renderer.scrollTop, 0);
assert.equal(editor.completer.popup.renderer.scroller.textContent, "some");
assert.equal(editor.completer.popup.renderer.scroller.textContent, "some ");
sendKey("Return");
assert.equal(editor.getValue(), "some");
sendKey(" ");
Expand Down
9 changes: 5 additions & 4 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -2838,21 +2838,22 @@ config.defineOptions(Editor.prototype, "editor", {
set: function(message) {
if (!this.$updatePlaceholder) {
this.$updatePlaceholder = function() {
var value = this.session && (this.renderer.$composition || this.getValue());
if (value && this.renderer.placeholderNode) {
var hasValue = this.session && (this.renderer.$composition ||
this.session.getLength() > 1 || this.session.getLine(0).length > 0);
if (hasValue && this.renderer.placeholderNode) {
this.renderer.off("afterRender", this.$updatePlaceholder);
dom.removeCssClass(this.container, "ace_hasPlaceholder");
this.renderer.placeholderNode.remove();
this.renderer.placeholderNode = null;
} else if (!value && !this.renderer.placeholderNode) {
} else if (!hasValue && !this.renderer.placeholderNode) {
this.renderer.on("afterRender", this.$updatePlaceholder);
dom.addCssClass(this.container, "ace_hasPlaceholder");
var el = dom.createElement("div");
el.className = "ace_placeholder";
el.textContent = this.$placeholder || "";
this.renderer.placeholderNode = el;
this.renderer.content.appendChild(this.renderer.placeholderNode);
} else if (!value && this.renderer.placeholderNode) {
} else if (!hasValue && this.renderer.placeholderNode) {
this.renderer.placeholderNode.textContent = this.$placeholder || "";
}
}.bind(this);
Expand Down

0 comments on commit 64c7758

Please sign in to comment.