Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom input TV type #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Custom input TV type #9

wants to merge 2 commits into from

Conversation

evd
Copy link

@evd evd commented Dec 1, 2012

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

@danyaPostfactum
Copy link
Owner

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
Copy link
Author

evd commented Dec 26, 2012

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
Copy link

argnist commented Jun 27, 2013

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

@pixelchutes
Copy link

👍 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
Copy link

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
Copy link
Author

evd commented Feb 27, 2015

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

mrhaw commented Aug 19, 2018

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

@mrhaw
Copy link

mrhaw commented Aug 19, 2018

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

@mindeffects
Copy link

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
Copy link

mrhaw commented Sep 13, 2018

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
Copy link

mindeffects commented Sep 13, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants