Convert Figma logo to code with AI

ajaxorg logoace

Ace (Ajax.org Cloud9 Editor)

26,643
5,273
26,643
152

Top Related Projects

In-browser code editor (version 5, legacy)

A browser based code editor

17,402

A terminal for the web

43,060

Quill is a modern WYSIWYG editor built for compatibility and extensibility

19,096

Lexical is an extensible text editor framework that provides excellent reliability, accessibility and performance.

12,224

Lightweight, robust, elegant syntax highlighting.

Quick Overview

Ace is a high-performance code editor for the web, written in JavaScript. It can be easily embedded in any web page and provides features like syntax highlighting, auto-completion, and code folding for over 110 languages. Ace is the editor that powers many popular platforms, including GitHub, Cloud9 IDE, and Wikipedia.

Pros

  • Highly customizable and extensible
  • Supports a wide range of programming languages and file formats
  • Excellent performance, even with large files
  • Active community and regular updates

Cons

  • Learning curve for advanced customization
  • Some users report occasional rendering issues in certain browsers
  • Mobile support is limited compared to desktop
  • Can be overkill for simple text editing needs

Code Examples

  1. Basic initialization:
const editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/javascript");

This code initializes an Ace editor in the element with id "editor", sets the theme to Monokai, and sets the language mode to JavaScript.

  1. Adding custom commands:
editor.commands.addCommand({
    name: 'saveFile',
    bindKey: {win: 'Ctrl-S',  mac: 'Command-S'},
    exec: function(editor) {
        // Your save logic here
        console.log('File saved!');
    }
});

This example adds a custom save command to the editor, bound to Ctrl-S (or Command-S on Mac).

  1. Listening for changes:
editor.session.on('change', function(delta) {
    console.log('The document changed');
});

This code adds an event listener that logs a message whenever the document content changes.

Getting Started

To get started with Ace, follow these steps:

  1. Include Ace in your HTML file:
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/ace.js" type="text/javascript" charset="utf-8"></script>
  1. Create a div element to hold the editor:
<div id="editor" style="height: 300px; width: 100%;"></div>
  1. Initialize the editor in your JavaScript:
const editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/javascript");
editor.setValue("console.log('Hello, Ace!');");

This will create a basic Ace editor with JavaScript syntax highlighting and the Monokai theme.

Competitor Comparisons

In-browser code editor (version 5, legacy)

Pros of CodeMirror 5

  • More extensive language support and syntax highlighting options
  • Better performance for large documents and complex syntax
  • Easier to customize and extend with a modular architecture

Cons of CodeMirror 5

  • Steeper learning curve for beginners
  • Less out-of-the-box features compared to Ace
  • Slightly larger file size, which may impact load times

Code Comparison

Ace:

var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/javascript");

CodeMirror 5:

var editor = CodeMirror.fromTextArea(document.getElementById("editor"), {
  mode: "javascript",
  theme: "monokai"
});

Both Ace and CodeMirror 5 are popular code editor libraries for web applications. Ace offers a more straightforward setup process and a wider range of pre-built features, making it easier for beginners to get started. However, CodeMirror 5 provides more flexibility and customization options, which can be beneficial for advanced users and complex projects.

CodeMirror 5 excels in performance for large documents and offers more extensive language support, while Ace has a smaller file size and may be more suitable for simpler use cases. Ultimately, the choice between the two depends on the specific requirements of your project and your familiarity with each library.

A browser based code editor

Pros of Monaco Editor

  • More advanced IntelliSense and code completion features
  • Better TypeScript support and integration
  • Wider range of language services and built-in features

Cons of Monaco Editor

  • Larger file size and potentially heavier resource usage
  • Steeper learning curve for customization and configuration
  • Less flexibility for lightweight implementations

Code Comparison

Monaco Editor:

import * as monaco from 'monaco-editor';

monaco.editor.create(document.getElementById('container'), {
    value: 'function hello() {\n\tconsole.log("Hello world!");\n}',
    language: 'javascript'
});

Ace:

var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/javascript");
editor.setValue("function hello() {\n\tconsole.log('Hello world!');\n}");

Both Monaco Editor and Ace are powerful web-based code editors, but they cater to different use cases. Monaco Editor excels in providing a more comprehensive IDE-like experience with advanced features, while Ace offers a lighter, more customizable solution for simpler editing needs. The choice between the two depends on the specific requirements of your project, such as the level of language support needed, performance considerations, and the desired balance between features and simplicity.

17,402

A terminal for the web

Pros of xterm.js

  • Specialized for terminal emulation, providing a more authentic terminal experience
  • Lightweight and focused on terminal functionality
  • Better support for ANSI escape codes and terminal-specific features

Cons of xterm.js

  • Limited to terminal-like interfaces, less versatile for general text editing
  • Fewer built-in features for syntax highlighting and code editing
  • Smaller community and ecosystem compared to Ace

Code Comparison

xterm.js:

const term = new Terminal();
term.open(document.getElementById('terminal'));
term.write('Hello from \x1B[1;3;31mxterm.js\x1B[0m $ ');

Ace:

const editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/javascript");
editor.setValue("function hello() {\n    console.log('Hello from Ace!');\n}");

Summary

xterm.js is a specialized library for terminal emulation, offering a more authentic terminal experience with better support for ANSI escape codes. It's lightweight and focused on terminal functionality. However, it's limited to terminal-like interfaces and has fewer features for general text editing compared to Ace.

Ace, on the other hand, is a full-featured code editor for the web, with robust syntax highlighting, multiple language support, and a larger ecosystem. It's more versatile for various text editing tasks but may be overkill for simple terminal emulation.

Choose xterm.js for projects requiring a terminal-like interface, and Ace for more complex code editing and syntax highlighting needs.

43,060

Quill is a modern WYSIWYG editor built for compatibility and extensibility

Pros of Quill

  • More modern and lightweight architecture
  • Better support for rich text editing and formatting
  • Easier to customize and extend with modules

Cons of Quill

  • Smaller community and ecosystem compared to Ace
  • Less suitable for code editing and syntax highlighting
  • Fewer language modes and themes available out-of-the-box

Code Comparison

Ace:

var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/javascript");

Quill:

var quill = new Quill('#editor', {
  theme: 'snow',
  modules: {
    toolbar: [['bold', 'italic'], ['link', 'image']]
  }
});

Both Ace and Quill are popular open-source text editors for web applications, but they serve different purposes. Ace is primarily designed for code editing, offering features like syntax highlighting and code folding. Quill, on the other hand, focuses on rich text editing and is better suited for content creation and formatting.

Ace has a larger community and more extensive language support, making it ideal for developer-oriented applications. Quill's modern architecture and modular design make it easier to customize and extend, particularly for rich text editing scenarios.

When choosing between the two, consider your specific use case and requirements. Ace is the go-to choice for code editing, while Quill excels in rich text editing and content creation applications.

19,096

Lexical is an extensible text editor framework that provides excellent reliability, accessibility and performance.

Pros of Lexical

  • Modern architecture: Built with React and TypeScript, offering better integration with modern web frameworks
  • Extensibility: Provides a plugin system for easy customization and feature addition
  • Accessibility: Strong focus on accessibility features out-of-the-box

Cons of Lexical

  • Learning curve: Requires familiarity with React and modern JavaScript concepts
  • Limited language support: Primarily focused on rich text editing, less suitable for code editing
  • Smaller community: Being newer, it has a smaller ecosystem and fewer resources compared to Ace

Code Comparison

Lexical (React component):

import {LexicalComposer} from '@lexical/react/LexicalComposer';
import {RichTextPlugin} from '@lexical/react/LexicalRichTextPlugin';

function Editor() {
  return (
    <LexicalComposer>
      <RichTextPlugin />
    </LexicalComposer>
  );
}

Ace (Vanilla JavaScript):

var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/javascript");
editor.setValue("function foo() {\n    console.log('Hello World');\n}");
12,224

Lightweight, robust, elegant syntax highlighting.

Pros of Prism

  • Lightweight and fast, with a smaller footprint than Ace
  • Easy to set up and use, requiring minimal configuration
  • Extensive language support out of the box

Cons of Prism

  • Limited editing capabilities, primarily focused on syntax highlighting
  • Less customizable than Ace for advanced use cases
  • Lacks features like line numbers and code folding by default

Code Comparison

Prism:

Prism.highlightAll();

Ace:

var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/javascript");

Summary

Prism is a lightweight syntax highlighting library that excels in simplicity and ease of use. It's ideal for projects that require quick implementation of code highlighting without extensive editing features. Ace, on the other hand, is a full-featured code editor that offers more advanced capabilities and customization options, making it suitable for complex web-based coding environments.

While Prism can be set up with a single line of code, Ace requires more configuration but provides a richer set of features. The choice between the two depends on the specific needs of your project, balancing between simplicity and advanced functionality.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Ace (Ajax.org Cloud9 Editor)

Build Status npm

Note: The new site at http://ace.c9.io contains all the info below along with an embedding guide and all the other resources you need to get started with Ace.

Ace is a standalone code editor written in JavaScript. Our goal is to create a browser based editor that matches and extends the features, usability and performance of existing native editors such as TextMate, Vim or Eclipse. It can be easily embedded in any web page or JavaScript application. Ace is developed as the primary editor for Cloud9 IDE and the successor of the Mozilla Skywriter (Bespin) Project.

Features

  • Syntax highlighting for over 120 languages (TextMate/Sublime/.tmlanguage files can be imported)
  • Over 20 themes (TextMate/Sublime/.tmtheme files can be imported)
  • Automatic indent and outdent
  • An optional command line
  • Handles huge documents (at last check, 4,000,000 lines is the upper limit)
  • Fully customizable key bindings including vim and Emacs modes
  • Search and replace with regular expressions
  • Highlight matching parentheses
  • Toggle between soft tabs and real tabs
  • Displays hidden characters
  • Drag and drop text using the mouse
  • Line wrapping
  • Code folding
  • Multiple cursors and selections
  • Live syntax checker (currently JavaScript/CoffeeScript/CSS/XQuery)
  • Cut, copy, and paste functionality

Take Ace for a spin!

Check out the Ace live demo or get a Cloud9 IDE account to experience Ace while editing one of your own GitHub projects.

If you want, you can use Ace as a textarea replacement thanks to the Ace Bookmarklet.

Embedding Ace

Ace can be easily embedded into any existing web page. You can either use one of pre-packaged versions of ace (just copy one of src* subdirectories somewhere into your project), or use requireJS to load contents of lib/ace as ace

The easiest version is simply:

<div id="editor">some text</div>
<script src="src/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
    var editor = ace.edit("editor");
</script>

Exploring configuration options Configuring-Ace

With "editor" being the id of the DOM element, which should be converted to an editor. Note that this element must be explicitly sized and positioned absolute or relative for Ace to work. e.g.

#editor {
    position: absolute;
    width: 500px;
    height: 400px;
}

To change the theme simply include the Theme's JavaScript file

<script src="src/theme-twilight.js" type="text/javascript" charset="utf-8"></script>

and configure the editor to use the theme:

editor.setTheme("ace/theme/twilight");

By default the editor only supports plain text mode; many other languages are available as separate modules. After including the mode's JavaScript file:

<script src="src/mode-javascript.js" type="text/javascript" charset="utf-8"></script>

The mode can then be used like this:

var JavaScriptMode = ace.require("ace/mode/javascript").Mode;
editor.session.setMode(new JavaScriptMode());

to destroy editor use

editor.destroy();
editor.container.remove();

Documentation

Additional usage information, including events to listen to and extending syntax highlighters, can be found on the main Ace website.

You can also find API documentation at https://ajaxorg.github.io/ace-api-docs/.

Also check out the sample code for the kitchen sink demo app.

If you still need help, feel free to ask a question on our discussions page.

Running Ace

After the checkout Ace works out of the box. No build step is required. To try it out, simply start the bundled mini HTTP server using Node.JS

node ./static.js

The editor can then be opened at http://localhost:8888/kitchen-sink.html.

To open the editor with a file:/// URL see the wiki.

Building Ace

You do not generally need to build ACE. The ace-builds repository endeavours to maintain the latest build, and you can just copy one of src* subdirectories somewhere into your project.

However, all you need is Node.js and npm installed to package ACE. Just run npm install in the ace folder to install dependencies:

npm install
node ./Makefile.dryice.js

To package Ace, we use the dryice build tool developed by the Mozilla Skywriter team. Call node Makefile.dryice.js on the command-line to start the packing. This build script accepts the following options

-m                 minify build files with uglify-js          
-nc                namespace require and define calls with "ace"
-bm                builds the bookmarklet version
--target ./path    specify relative path for output folder (default value is "./build")

To generate all the files in the ace-builds repository, run node Makefile.dryice.js full --target ../ace-builds

Running the Unit Tests

The Ace unit tests can run on node.js. Assuming you have already done npm install, just call:

npm run test

You can also run the tests in your browser by serving:

http://localhost:8888/src/test/tests.html

This makes debugging failing tests much easier.

Contributing

Ace is a community project and wouldn't be what it is without contributions! We actively encourage and support contributions. The Ace source code is released under the BSD License. This license is very simple, and is friendly to all kinds of projects, whether open source or not. Take charge of your editor and add your favorite language highlighting and keybindings!

Feel free to fork and improve/enhance Ace any way you want. If you feel that the editor or the Ace community will benefit from your changes, please open a pull request. For more information on our contributing guidelines, see CONTRIBUTING.md.

NPM DownloadsLast 30 Days