How to display file content in Ace editor
I am testing ace-editor to display large text files from server. Because it can handle files up to 4 million lines and highlight text, it makes it a good candidate.
I tried to understand Document and EditSession from Ace editor. In my opinion it could be told to the ace editor to read from the file and display it.
I am using createEditSessiont () to create a session and point to a document. From the api documentation:
createEditSession (document | string text, TextMode)
Document: required. If the text is a document, it associates an EditSession with it. Otherwise, a new document is created with the original text
Here is my code:
<script src="../src/ace.js"></script>
<script>
var docSession = new ace.createEditSession("../Files/myFile.log", "ace/mode/plain_text");
var editor = ace.edit("editor");
editor.setSession(docSession);
editor.setTheme("ace/theme/dawn");
</script>
Unfortunately, all that appears on the page is "../Files/myFile.log". I am assuming that it creates another file with this text instead of reading the document. How do I correctly tell it to display the contents of myFile.log?
source to share
Ace does not process files in any way, it is only an editor frontend.
The document in the createEditSessions definition is an instance of an Aces Document object , not a file.
To upload a file to ace, you need to get its content from the server using an ajax call. something like https://github.com/ajaxorg/ace/blob/v1.1.7/demo/kitchen-sink/doclist.js#L164
source to share