danyaPostfactum / modx-ace

ACE editor integration into MODx
24 stars 23 forks source link

Custom input TV type #9

Open evd opened 11 years ago

evd commented 11 years ago

Add new input TV type 'codetext' with ACE Editor.

danyaPostfactum commented 11 years ago

Could you explain the utility of this tv type? May be you can describe some use cases..

What about handling richtext tv's when use_editor system setting is disabled ? Can it replace the use of codetext tv ?

evd commented 11 years ago

For example you can create TV for edit html markup and snippets call with highlight for sidebar. Handling richtext tvs is also solution, but I think Custom TV is more flexible, you can leave richtext for content field and text editor with highlight for sidebar TV.

argnist commented 11 years ago

Например, я пытался добавить TV, в котором хранится код, сгенерированный конструктором яндекс карт. Ричтекст вообще не выводил этот код, текстовая область оставляла только тег "<"/script">", а вот Ace-область здесь была бы очень кстати.

pixelchutes commented 10 years ago

:+1: Love this! Miss this feature from CodeMirror integration and MODX Evo... This brings it back with Ace and Revo!

I am curious if codetext TV type is technically required? Would be nice to see a compatible version that does not require re-mapping TV types. Would be great to have the option to work with "textarea" TV input types, and not limited to "Rich Text."

christianseel commented 10 years ago

Why is this still not merged? It works great and is absolutely useful. I don't think that it's good if we use ACE for all "textarea" TVs - they might be used for non-code content. So the new TV type makes absolutely sense.

evd commented 9 years ago

Who still need ace editor for some TVs can use this plugin:

<?php
//Apply ace editor to TV with id 5 and 7
$tvs = array(
    array(
        'id' => 5,
        'height' => '600px',
        'mimeType' => 'application/json'
    ),
    array(
        'id' => 7,
        'height' => '300px',
        'mimeType' => 'text/html'
    )
);

if ($modx->event->name != 'OnDocFormRender') {
    return;
}

if ($modx->getOption('which_element_editor', null, 'Ace') !== 'Ace') {
    return;
}

$script = '';
foreach ($tvs as $tv) {
    $id = is_array($tv) ? $tv['id'] : $tv;
    $height = isset($tv['height']) ? $tv['height'] : '';
    $mimeType = isset($tv['mimeType']) ? $tv['mimeType'] : '';
    $tvId = '#tv' . $id;
    $setHeightScript = !empty($height) ? 'this.style.height="' . $height . '";' : '';
    $aceScript = 'MODx.ux.Ace.replaceTextAreas([this], "' . $mimeType . '");';
    $script .= 'Ext.each(Ext.query("' . $tvId . '"), function() { ' . $setHeightScript . $aceScript . '});' . PHP_EOL;
}

if ($script) {
    $modx->controller->addHtml('<script>Ext.onReady(function() {' . $script . '});</script>');
}

Plugin listen OnDocFormRender event and must be execute after Ace plugin, so set priority something like 10 or higher. TV type must be textarea.

sonicpunk commented 8 years ago

In my MODX install when I use this plugin, the required theming assets for ACE do get the correct path screen shot 2016-02-04 at 10 23 54

mindeffects commented 8 years ago

THIS. IS. AWESOME. @evd !!! Works like a charm (I use priotity 99)! My ACE rows have a height of "18.5px" so I use a multiple of it, like 296px to get 16 rows. And with the fullscreen option of ACE, coding "inside of MODX" is fun again! :-D THANKS!!!

mindeffects commented 8 years ago

I would still like to see the new TV-type merged into ACE. ;-)

Maybe "Textarea ACE" would be a "better" name for the new TV-type? Would sort just below "Textarea" and would make it clear, that this is "ACE only".

mindeffects commented 6 years ago

Did anybody find a solution for <textarea class="ace_text-input" ...</textarea> not having the correct width? This makes first time editing no real fun, because the cursor stays on the far left side, in column 1. After going fullscreen mode everything is fine, even when leaving fullscreen mode again. Seems to be an "init" problem. Is there a cure?

mrhaw commented 6 years ago

Yes we need to get this fixed. Bookmarked and will report back if I find a fix

mrhaw commented 6 years ago

Duh! Changing theme from tomorrow_night_eighties to textmate removed the issue!

mindeffects commented 6 years ago

Wow, that was easy! Now let's make "textmate" the default template instead of "chrome". :-D

The settings array $tvs should be generated automagically by grabbing all TVs with the right input type and getting the options from the TV definition.

Looks like an new TV-type Textarea ACE is needed. My skills are to limited to do this. :-( Anybody?

mrhaw commented 6 years ago

Looks like an new TV-type Textarea ACE is needed. My skills are to limited to do this. :-( Anybody?

YES!!!!!!! I have used winmerge to compare files and css line by line. I can't figure this one out!

mindeffects commented 6 years ago

Strange. Seem's like a job for the masters with write access.

Btw: Besides textmate, the themes solarized_dark and solarized_light also work fine.